Chromium Code Reviews| Index: Source/platform/heap/Heap.h |
| diff --git a/Source/platform/heap/Heap.h b/Source/platform/heap/Heap.h |
| index d28cac06c23c38209c4bfe9e030d5e477a8aaa0f..291429b438edc8636ad85f02d2228033c388d5e7 100644 |
| --- a/Source/platform/heap/Heap.h |
| +++ b/Source/platform/heap/Heap.h |
| @@ -1413,6 +1413,44 @@ public: |
| } |
| }; |
| +template<typename T, size_t inlineCapacity = 0> |
| +class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { |
| +public: |
| + HeapDeque() { } |
| + |
| + explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(size) |
| + { |
| + } |
| + |
| + HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocator>(size, val) |
| + { |
| + } |
| + |
| + HeapDeque<T, 0>& operator=(const HeapDeque& other) |
| + { |
| + HeapDeque<T> copy(other); |
| + swap(copy); |
| + return *this; |
| + } |
| + |
| + inline void swap(HeapDeque& other) |
| + { |
| + Deque<T, inlineCapacity, HeapAllocator>::swap(other); |
|
wibling-chromium
2014/04/08 10:49:40
NIT: Consider adding a comment about this only wor
Erik Corry
2014/04/08 11:48:53
Done.
|
| + } |
| + |
| + template<size_t otherCapacity> |
| + HeapDeque(const HeapDeque<T, otherCapacity>& other) |
| + : Deque<T, inlineCapacity, HeapAllocator>(other) |
| + { |
| + } |
| + |
| + template<typename U> |
| + void append(const U& other) |
| + { |
| + Deque<T, inlineCapacity, HeapAllocator>::append(other); |
| + } |
| +}; |
| + |
| template<typename T> |
| struct ThreadingTrait<Member<T> > { |
| static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| @@ -1453,6 +1491,11 @@ struct ThreadingTrait<HeapVectorBacking<T, Traits> > { |
| static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| }; |
| +template<typename T, size_t inlineCapacity> |
| +struct ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator> > { |
| + static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| +}; |
| + |
| template<typename Table> |
| struct ThreadingTrait<HeapHashTableBacking<Table> > { |
| typedef typename Table::KeyType Key; |
| @@ -1471,10 +1514,13 @@ struct ThreadingTrait<HeapHashSet<T, U, V> > : public ThreadingTrait<HashSet<T, |
| template<typename T, size_t inlineCapacity> |
| struct ThreadingTrait<HeapVector<T, inlineCapacity> > : public ThreadingTrait<Vector<T, inlineCapacity, HeapAllocator> > { }; |
| +template<typename T, size_t inlineCapacity> |
| +struct ThreadingTrait<HeapDeque<T, inlineCapacity> > : public ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator> > { }; |
| + |
| // The standard implementation of GCInfoTrait<T>::get() just returns a static |
| -// from the class T, but we can't do that for HashMap, HashSet and Vector |
| -// because they are in WTF and know nothing of GCInfos. Instead we have a |
| -// specialization of GCInfoTrait for these three classes here. |
| +// from the class T, but we can't do that for HashMap, HashSet, Deque and |
| +// Vector because they are in WTF and know nothing of GCInfos. Instead we have |
| +// a specialization of GCInfoTrait for these three classes here. |
| template<typename Key, typename Value, typename T, typename U, typename V> |
| struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { |
| @@ -1532,6 +1578,36 @@ const GCInfo GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> >::info = { |
| inlineCapacity && VectorTraits<T>::needsDestruction, |
| }; |
| +template<typename T> |
| +struct GCInfoTrait<Deque<T, 0, HeapAllocator> > { |
| + static const GCInfo* get() { return &info; } |
| + static const GCInfo info; |
| +}; |
| + |
| +template<typename T> |
| +const GCInfo GCInfoTrait<Deque<T, 0, HeapAllocator> >::info = { |
| + TraceTrait<Deque<T, 0, HeapAllocator> >::trace, |
| + 0, |
| + false, // Deque needs no finalizer if it has no inline capacity. |
| +}; |
| + |
| +template<typename T, size_t inlineCapacity> |
| +struct GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { |
| + static const GCInfo* get() { return &info; } |
| + static const GCInfo info; |
| +}; |
| + |
| +template<typename T, size_t inlineCapacity> |
| +struct FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator> > : public FinalizerTraitImpl<Deque<T, inlineCapacity, HeapAllocator>, true> { }; |
| + |
| +template<typename T, size_t inlineCapacity> |
| +const GCInfo GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> >::info = { |
| + TraceTrait<Deque<T, inlineCapacity, HeapAllocator> >::trace, |
| + FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator> >::finalize, |
| + // Finalizer is needed to destruct things stored in the inline capacity. |
| + inlineCapacity && VectorTraits<T>::needsDestruction, |
| +}; |
| + |
| template<typename T, typename Traits> |
| struct GCInfoTrait<HeapVectorBacking<T, Traits> > { |
| static const GCInfo* get() { return &info; } |
| @@ -1694,7 +1770,7 @@ struct TraceTrait<HeapVectorBacking<T, Traits> > { |
| typedef HeapVectorBacking<T, Traits> Backing; |
| static void trace(WebCore::Visitor* visitor, void* self) |
| { |
| - COMPILE_ASSERT(!Traits::isWeak, WeDontSupportWeaknessInHeapVectors); |
| + COMPILE_ASSERT(!Traits::isWeak, WeDontSupportWeaknessInHeapVectors); // We don't support it in HeapDeques either. |
|
Mads Ager (chromium)
2014/04/08 10:46:17
Put the comment on its own line above the COMPILE_
wibling-chromium
2014/04/08 10:49:40
WeDontSupportWeaknessInHeapVectorsOrDeques?
Erik Corry
2014/04/08 11:48:53
Done.
|
| if (WTF::ShouldBeTraced<Traits>::value) |
| CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, false, false, HeapVectorBacking<T, Traits>, void>::mark(visitor, self); |
| } |
| @@ -1762,6 +1838,8 @@ template<typename T, typename U, typename V> |
| struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { }; |
| template<typename T, size_t inlineCapacity> |
| struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> > { }; |
| +template<typename T, size_t inlineCapacity> |
| +struct GCInfoTrait<HeapDeque<T, inlineCapacity> > : public GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { }; |
| template<typename T> |
| struct IfWeakMember; |