OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 inline Deque<T, 0, Allocator>& Deque<T, inlineCapacity, Allocator>::operator
=(const Deque& other) | 239 inline Deque<T, 0, Allocator>& Deque<T, inlineCapacity, Allocator>::operator
=(const Deque& other) |
240 { | 240 { |
241 Deque<T> copy(other); | 241 Deque<T> copy(other); |
242 swap(copy); | 242 swap(copy); |
243 return *this; | 243 return *this; |
244 } | 244 } |
245 | 245 |
246 template<typename T, size_t inlineCapacity, typename Allocator> | 246 template<typename T, size_t inlineCapacity, typename Allocator> |
247 inline void Deque<T, inlineCapacity, Allocator>::destroyAll() | 247 inline void Deque<T, inlineCapacity, Allocator>::destroyAll() |
248 { | 248 { |
249 if (m_start <= m_end) | 249 if (m_start <= m_end) { |
250 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffe
r() + m_end); | 250 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffe
r() + m_end); |
251 else { | 251 m_buffer.clearUnusedSlots(m_buffer.buffer() + m_start, m_buffer.buff
er() + m_end); |
| 252 } else { |
252 TypeOperations::destruct(m_buffer.buffer(), m_buffer.buffer() + m_en
d); | 253 TypeOperations::destruct(m_buffer.buffer(), m_buffer.buffer() + m_en
d); |
| 254 m_buffer.clearUnusedSlots(m_buffer.buffer(), m_buffer.buffer() + m_e
nd); |
253 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffe
r() + m_buffer.capacity()); | 255 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffe
r() + m_buffer.capacity()); |
| 256 m_buffer.clearUnusedSlots(m_buffer.buffer() + m_start, m_buffer.buff
er() + m_buffer.capacity()); |
254 } | 257 } |
255 } | 258 } |
256 | 259 |
257 // Off-GC-heap deques: Destructor should be called. | 260 // Off-GC-heap deques: Destructor should be called. |
258 // On-GC-heap deques: Destructor should be called for inline buffers | 261 // On-GC-heap deques: Destructor should be called for inline buffers |
259 // (if any) but destructor shouldn't be called for vector backing since | 262 // (if any) but destructor shouldn't be called for vector backing since |
260 // it is managed by the traced GC heap. | 263 // it is managed by the traced GC heap. |
261 template<typename T, size_t inlineCapacity, typename Allocator> | 264 template<typename T, size_t inlineCapacity, typename Allocator> |
262 inline void Deque<T, inlineCapacity, Allocator>::finalize() | 265 inline void Deque<T, inlineCapacity, Allocator>::finalize() |
263 { | 266 { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 else | 371 else |
369 --m_start; | 372 --m_start; |
370 new (NotNull, &m_buffer.buffer()[m_start]) T(value); | 373 new (NotNull, &m_buffer.buffer()[m_start]) T(value); |
371 } | 374 } |
372 | 375 |
373 template<typename T, size_t inlineCapacity, typename Allocator> | 376 template<typename T, size_t inlineCapacity, typename Allocator> |
374 inline void Deque<T, inlineCapacity, Allocator>::removeFirst() | 377 inline void Deque<T, inlineCapacity, Allocator>::removeFirst() |
375 { | 378 { |
376 ASSERT(!isEmpty()); | 379 ASSERT(!isEmpty()); |
377 TypeOperations::destruct(&m_buffer.buffer()[m_start], &m_buffer.buffer()
[m_start + 1]); | 380 TypeOperations::destruct(&m_buffer.buffer()[m_start], &m_buffer.buffer()
[m_start + 1]); |
| 381 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start], &m_buffer.buffer(
)[m_start + 1]); |
378 if (m_start == m_buffer.capacity() - 1) | 382 if (m_start == m_buffer.capacity() - 1) |
379 m_start = 0; | 383 m_start = 0; |
380 else | 384 else |
381 ++m_start; | 385 ++m_start; |
382 } | 386 } |
383 | 387 |
384 template<typename T, size_t inlineCapacity, typename Allocator> | 388 template<typename T, size_t inlineCapacity, typename Allocator> |
385 inline void Deque<T, inlineCapacity, Allocator>::removeLast() | 389 inline void Deque<T, inlineCapacity, Allocator>::removeLast() |
386 { | 390 { |
387 ASSERT(!isEmpty()); | 391 ASSERT(!isEmpty()); |
388 if (!m_end) | 392 if (!m_end) |
389 m_end = m_buffer.capacity() - 1; | 393 m_end = m_buffer.capacity() - 1; |
390 else | 394 else |
391 --m_end; | 395 --m_end; |
392 TypeOperations::destruct(&m_buffer.buffer()[m_end], &m_buffer.buffer()[m
_end + 1]); | 396 TypeOperations::destruct(&m_buffer.buffer()[m_end], &m_buffer.buffer()[m
_end + 1]); |
| 397 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_end], &m_buffer.buffer()[
m_end + 1]); |
393 } | 398 } |
394 | 399 |
395 template<typename T, size_t inlineCapacity, typename Allocator> | 400 template<typename T, size_t inlineCapacity, typename Allocator> |
396 inline void Deque<T, inlineCapacity, Allocator>::remove(iterator& it) | 401 inline void Deque<T, inlineCapacity, Allocator>::remove(iterator& it) |
397 { | 402 { |
398 remove(it.m_index); | 403 remove(it.m_index); |
399 } | 404 } |
400 | 405 |
401 template<typename T, size_t inlineCapacity, typename Allocator> | 406 template<typename T, size_t inlineCapacity, typename Allocator> |
402 inline void Deque<T, inlineCapacity, Allocator>::remove(const_iterator& it) | 407 inline void Deque<T, inlineCapacity, Allocator>::remove(const_iterator& it) |
403 { | 408 { |
404 remove(it.m_index); | 409 remove(it.m_index); |
405 } | 410 } |
406 | 411 |
407 template<typename T, size_t inlineCapacity, typename Allocator> | 412 template<typename T, size_t inlineCapacity, typename Allocator> |
408 inline void Deque<T, inlineCapacity, Allocator>::remove(size_t position) | 413 inline void Deque<T, inlineCapacity, Allocator>::remove(size_t position) |
409 { | 414 { |
410 if (position == m_end) | 415 if (position == m_end) |
411 return; | 416 return; |
412 | 417 |
413 T* buffer = m_buffer.buffer(); | 418 T* buffer = m_buffer.buffer(); |
414 TypeOperations::destruct(&buffer[position], &buffer[position + 1]); | 419 TypeOperations::destruct(&buffer[position], &buffer[position + 1]); |
415 | 420 |
416 // Find which segment of the circular buffer contained the remove elemen
t, and only move elements in that part. | 421 // Find which segment of the circular buffer contained the remove elemen
t, and only move elements in that part. |
417 if (position >= m_start) { | 422 if (position >= m_start) { |
418 TypeOperations::moveOverlapping(buffer + m_start, buffer + position,
buffer + m_start + 1); | 423 TypeOperations::moveOverlapping(buffer + m_start, buffer + position,
buffer + m_start + 1); |
| 424 m_buffer.clearUnusedSlots(buffer + m_start, buffer + m_start + 1); |
419 m_start = (m_start + 1) % m_buffer.capacity(); | 425 m_start = (m_start + 1) % m_buffer.capacity(); |
420 } else { | 426 } else { |
421 TypeOperations::moveOverlapping(buffer + position + 1, buffer + m_en
d, buffer + position); | 427 TypeOperations::moveOverlapping(buffer + position + 1, buffer + m_en
d, buffer + position); |
| 428 m_buffer.clearUnusedSlots(buffer + m_end - 1, buffer + m_end); |
422 m_end = (m_end - 1 + m_buffer.capacity()) % m_buffer.capacity(); | 429 m_end = (m_end - 1 + m_buffer.capacity()) % m_buffer.capacity(); |
423 } | 430 } |
424 } | 431 } |
425 | 432 |
426 template<typename T, size_t inlineCapacity, typename Allocator> | 433 template<typename T, size_t inlineCapacity, typename Allocator> |
427 inline DequeIteratorBase<T, inlineCapacity, Allocator>::DequeIteratorBase() | 434 inline DequeIteratorBase<T, inlineCapacity, Allocator>::DequeIteratorBase() |
428 : m_deque(0) | 435 : m_deque(0) |
429 { | 436 { |
430 } | 437 } |
431 | 438 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 529 } |
523 if (m_buffer.hasOutOfLineBuffer()) | 530 if (m_buffer.hasOutOfLineBuffer()) |
524 Allocator::markNoTracing(visitor, m_buffer.buffer()); | 531 Allocator::markNoTracing(visitor, m_buffer.buffer()); |
525 } | 532 } |
526 | 533 |
527 } // namespace WTF | 534 } // namespace WTF |
528 | 535 |
529 using WTF::Deque; | 536 using WTF::Deque; |
530 | 537 |
531 #endif // WTF_Deque_h | 538 #endif // WTF_Deque_h |
OLD | NEW |