| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 template <typename T, size_t inlineCapacity = 0, typename Allocator = PartitionA
llocator> | 45 template <typename T, size_t inlineCapacity = 0, typename Allocator = PartitionA
llocator> |
| 46 class Deque : public ConditionalDestructor<Deque<T, INLINE_CAPACITY, Allocator>,
(INLINE_CAPACITY == 0) && Allocator::isGarbageCollected> { | 46 class Deque : public ConditionalDestructor<Deque<T, INLINE_CAPACITY, Allocator>,
(INLINE_CAPACITY == 0) && Allocator::isGarbageCollected> { |
| 47 WTF_USE_ALLOCATOR(Deque, Allocator); | 47 WTF_USE_ALLOCATOR(Deque, Allocator); |
| 48 public: | 48 public: |
| 49 typedef DequeIterator<T, inlineCapacity, Allocator> iterator; | 49 typedef DequeIterator<T, inlineCapacity, Allocator> iterator; |
| 50 typedef DequeConstIterator<T, inlineCapacity, Allocator> const_iterator; | 50 typedef DequeConstIterator<T, inlineCapacity, Allocator> const_iterator; |
| 51 typedef std::reverse_iterator<iterator> reverse_iterator; | 51 typedef std::reverse_iterator<iterator> reverse_iterator; |
| 52 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | 52 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 53 | 53 |
| 54 Deque(); | 54 Deque(); |
| 55 Deque(const Deque<T, inlineCapacity, Allocator>&); | 55 Deque(const Deque&); |
| 56 Deque& operator=(const Deque&); | 56 Deque& operator=(const Deque&); |
| 57 Deque(Deque&&); |
| 58 Deque& operator=(Deque&&); |
| 57 | 59 |
| 58 void finalize(); | 60 void finalize(); |
| 59 void finalizeGarbageCollectedObject() { finalize(); } | 61 void finalizeGarbageCollectedObject() { finalize(); } |
| 60 | 62 |
| 61 void swap(Deque<T, inlineCapacity, Allocator>&); | 63 void swap(Deque&); |
| 62 | 64 |
| 63 size_t size() const { return m_start <= m_end ? m_end - m_start : m_end + m_
buffer.capacity() - m_start; } | 65 size_t size() const { return m_start <= m_end ? m_end - m_start : m_end + m_
buffer.capacity() - m_start; } |
| 64 bool isEmpty() const { return m_start == m_end; } | 66 bool isEmpty() const { return m_start == m_end; } |
| 65 | 67 |
| 66 iterator begin() { return iterator(this, m_start); } | 68 iterator begin() { return iterator(this, m_start); } |
| 67 iterator end() { return iterator(this, m_end); } | 69 iterator end() { return iterator(this, m_end); } |
| 68 const_iterator begin() const { return const_iterator(this, m_start); } | 70 const_iterator begin() const { return const_iterator(this, m_start); } |
| 69 const_iterator end() const { return const_iterator(this, m_end); } | 71 const_iterator end() const { return const_iterator(this, m_end); } |
| 70 reverse_iterator rbegin() { return reverse_iterator(end()); } | 72 reverse_iterator rbegin() { return reverse_iterator(end()); } |
| 71 reverse_iterator rend() { return reverse_iterator(begin()); } | 73 reverse_iterator rend() { return reverse_iterator(begin()); } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 void remove(iterator&); | 105 void remove(iterator&); |
| 104 void remove(const_iterator&); | 106 void remove(const_iterator&); |
| 105 | 107 |
| 106 void clear(); | 108 void clear(); |
| 107 | 109 |
| 108 template <typename Predicate> | 110 template <typename Predicate> |
| 109 iterator findIf(Predicate&); | 111 iterator findIf(Predicate&); |
| 110 | 112 |
| 111 template <typename VisitorDispatcher> void trace(VisitorDispatcher); | 113 template <typename VisitorDispatcher> void trace(VisitorDispatcher); |
| 112 | 114 |
| 115 static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canInitial
izeWithMemset, "Cannot initialize with memset if there is a vtable"); |
| 116 #if ENABLE(OILPAN) |
| 117 static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T>::v
alue || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NEW o
bjects that have trace methods into an off-heap Deque"); |
| 118 #endif |
| 119 static_assert(Allocator::isGarbageCollected || !IsPointerToGarbageCollectedT
ype<T>::value, "Cannot put raw pointers to garbage-collected classes into a Dequ
e. Use HeapDeque<Member<T>> instead."); |
| 120 |
| 113 private: | 121 private: |
| 114 friend class DequeIteratorBase<T, inlineCapacity, Allocator>; | 122 friend class DequeIteratorBase<T, inlineCapacity, Allocator>; |
| 115 | 123 |
| 116 class Buffer : public VectorBuffer<T, INLINE_CAPACITY, Allocator> { | 124 class Buffer : public VectorBuffer<T, INLINE_CAPACITY, Allocator> { |
| 117 WTF_MAKE_NONCOPYABLE(Buffer); | 125 WTF_MAKE_NONCOPYABLE(Buffer); |
| 118 private: | 126 private: |
| 119 using Base = VectorBuffer<T, INLINE_CAPACITY, Allocator>; | 127 using Base = VectorBuffer<T, INLINE_CAPACITY, Allocator>; |
| 120 using Base::m_size; | 128 using Base::m_size; |
| 121 | 129 |
| 122 public: | 130 public: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // postfix ++ intentionally omitted | 238 // postfix ++ intentionally omitted |
| 231 Iterator& operator--() { Base::decrement(); return *this; } | 239 Iterator& operator--() { Base::decrement(); return *this; } |
| 232 // postfix -- intentionally omitted | 240 // postfix -- intentionally omitted |
| 233 }; | 241 }; |
| 234 | 242 |
| 235 template <typename T, size_t inlineCapacity, typename Allocator> | 243 template <typename T, size_t inlineCapacity, typename Allocator> |
| 236 inline Deque<T, inlineCapacity, Allocator>::Deque() | 244 inline Deque<T, inlineCapacity, Allocator>::Deque() |
| 237 : m_start(0) | 245 : m_start(0) |
| 238 , m_end(0) | 246 , m_end(0) |
| 239 { | 247 { |
| 240 static_assert(!std::is_polymorphic<T>::value || !VectorTraits<T>::canInitial
izeWithMemset, "Cannot initialize with memset if there is a vtable"); | |
| 241 #if ENABLE(OILPAN) | |
| 242 static_assert(Allocator::isGarbageCollected || !AllowsOnlyPlacementNew<T>::v
alue || !NeedsTracing<T>::value, "Cannot put DISALLOW_NEW_EXCEPT_PLACEMENT_NEW o
bjects that have trace methods into an off-heap Deque"); | |
| 243 #endif | |
| 244 static_assert(Allocator::isGarbageCollected || !IsPointerToGarbageCollectedT
ype<T>::value, "Cannot put raw pointers to garbage-collected classes into a Dequ
e. Use HeapDeque<Member<T>> instead."); | |
| 245 } | 248 } |
| 246 | 249 |
| 247 template <typename T, size_t inlineCapacity, typename Allocator> | 250 template <typename T, size_t inlineCapacity, typename Allocator> |
| 248 inline Deque<T, inlineCapacity, Allocator>::Deque(const Deque<T, inlineCapacity,
Allocator>& other) | 251 inline Deque<T, inlineCapacity, Allocator>::Deque(const Deque& other) |
| 249 : m_buffer(other.m_buffer.capacity()) | 252 : m_buffer(other.m_buffer.capacity()) |
| 250 , m_start(other.m_start) | 253 , m_start(other.m_start) |
| 251 , m_end(other.m_end) | 254 , m_end(other.m_end) |
| 252 { | 255 { |
| 253 const T* otherBuffer = other.m_buffer.buffer(); | 256 const T* otherBuffer = other.m_buffer.buffer(); |
| 254 if (m_start <= m_end) { | 257 if (m_start <= m_end) { |
| 255 TypeOperations::uninitializedCopy(otherBuffer + m_start, otherBuffer + m
_end, m_buffer.buffer() + m_start); | 258 TypeOperations::uninitializedCopy(otherBuffer + m_start, otherBuffer + m
_end, m_buffer.buffer() + m_start); |
| 256 } else { | 259 } else { |
| 257 TypeOperations::uninitializedCopy(otherBuffer, otherBuffer + m_end, m_bu
ffer.buffer()); | 260 TypeOperations::uninitializedCopy(otherBuffer, otherBuffer + m_end, m_bu
ffer.buffer()); |
| 258 TypeOperations::uninitializedCopy(otherBuffer + m_start, otherBuffer + m
_buffer.capacity(), m_buffer.buffer() + m_start); | 261 TypeOperations::uninitializedCopy(otherBuffer + m_start, otherBuffer + m
_buffer.capacity(), m_buffer.buffer() + m_start); |
| 259 } | 262 } |
| 260 } | 263 } |
| 261 | 264 |
| 262 template <typename T, size_t inlineCapacity, typename Allocator> | 265 template <typename T, size_t inlineCapacity, typename Allocator> |
| 263 inline Deque<T, inlineCapacity, Allocator>& Deque<T, inlineCapacity, Allocator>:
:operator=(const Deque& other) | 266 inline Deque<T, inlineCapacity, Allocator>& Deque<T, inlineCapacity, Allocator>:
:operator=(const Deque& other) |
| 264 { | 267 { |
| 265 Deque<T> copy(other); | 268 Deque<T> copy(other); |
| 266 swap(copy); | 269 swap(copy); |
| 267 return *this; | 270 return *this; |
| 268 } | 271 } |
| 269 | 272 |
| 270 template <typename T, size_t inlineCapacity, typename Allocator> | 273 template <typename T, size_t inlineCapacity, typename Allocator> |
| 274 inline Deque<T, inlineCapacity, Allocator>::Deque(Deque&& other) |
| 275 : m_start(0) |
| 276 , m_end(0) |
| 277 { |
| 278 swap(other); |
| 279 } |
| 280 |
| 281 template <typename T, size_t inlineCapacity, typename Allocator> |
| 282 inline Deque<T, inlineCapacity, Allocator>& Deque<T, inlineCapacity, Allocator>:
:operator=(Deque&& other) |
| 283 { |
| 284 swap(other); |
| 285 return *this; |
| 286 } |
| 287 |
| 288 template <typename T, size_t inlineCapacity, typename Allocator> |
| 271 inline void Deque<T, inlineCapacity, Allocator>::destroyAll() | 289 inline void Deque<T, inlineCapacity, Allocator>::destroyAll() |
| 272 { | 290 { |
| 273 if (m_start <= m_end) { | 291 if (m_start <= m_end) { |
| 274 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_end); | 292 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_end); |
| 275 m_buffer.clearUnusedSlots(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_end); | 293 m_buffer.clearUnusedSlots(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_end); |
| 276 } else { | 294 } else { |
| 277 TypeOperations::destruct(m_buffer.buffer(), m_buffer.buffer() + m_end); | 295 TypeOperations::destruct(m_buffer.buffer(), m_buffer.buffer() + m_end); |
| 278 m_buffer.clearUnusedSlots(m_buffer.buffer(), m_buffer.buffer() + m_end); | 296 m_buffer.clearUnusedSlots(m_buffer.buffer(), m_buffer.buffer() + m_end); |
| 279 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_buffer.capacity()); | 297 TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_buffer.capacity()); |
| 280 m_buffer.clearUnusedSlots(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_buffer.capacity()); | 298 m_buffer.clearUnusedSlots(m_buffer.buffer() + m_start, m_buffer.buffer()
+ m_buffer.capacity()); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 struct NeedsTracing<Deque<T, N>> { | 625 struct NeedsTracing<Deque<T, N>> { |
| 608 static const bool value = false; | 626 static const bool value = false; |
| 609 }; | 627 }; |
| 610 #endif | 628 #endif |
| 611 | 629 |
| 612 } // namespace WTF | 630 } // namespace WTF |
| 613 | 631 |
| 614 using WTF::Deque; | 632 using WTF::Deque; |
| 615 | 633 |
| 616 #endif // WTF_Deque_h | 634 #endif // WTF_Deque_h |
| OLD | NEW |