OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ContiguousContainer_h | 5 #ifndef ContiguousContainer_h |
6 #define ContiguousContainer_h | 6 #define ContiguousContainer_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "wtf/Alignment.h" | 9 #include "wtf/Alignment.h" |
10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
11 #include "wtf/Compiler.h" | 11 #include "wtf/Compiler.h" |
12 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
13 #include "wtf/OwnPtr.h" | 13 #include "wtf/OwnPtr.h" |
14 #include "wtf/TypeTraits.h" | 14 #include "wtf/TypeTraits.h" |
15 #include "wtf/Utility.h" | |
16 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
17 #include <cstddef> | 16 #include <cstddef> |
18 #include <iterator> | 17 #include <iterator> |
| 18 #include <utility> |
19 | 19 |
20 namespace blink { | 20 namespace blink { |
21 | 21 |
22 // ContiguousContainer is a container which stores a list of heterogeneous | 22 // ContiguousContainer is a container which stores a list of heterogeneous |
23 // objects (in particular, of varying sizes), packed next to one another in | 23 // objects (in particular, of varying sizes), packed next to one another in |
24 // memory. Objects are never relocated, so it is safe to store pointers to them | 24 // memory. Objects are never relocated, so it is safe to store pointers to them |
25 // for the lifetime of the container (unless the object is removed). | 25 // for the lifetime of the container (unless the object is removed). |
26 // | 26 // |
27 // Memory is allocated in a series of buffers (with exponential growth). When an | 27 // Memory is allocated in a series of buffers (with exponential growth). When an |
28 // object is allocated, it is given only the space it requires (possibly with | 28 // object is allocated, it is given only the space it requires (possibly with |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 const BaseElementType& operator[](size_t index) const { return *(begin() + i
ndex); } | 144 const BaseElementType& operator[](size_t index) const { return *(begin() + i
ndex); } |
145 | 145 |
146 template <class DerivedElementType, typename... Args> | 146 template <class DerivedElementType, typename... Args> |
147 DerivedElementType& allocateAndConstruct(Args&&... args) | 147 DerivedElementType& allocateAndConstruct(Args&&... args) |
148 { | 148 { |
149 static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::valu
e, | 149 static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::valu
e, |
150 "Must use subclass of BaseElementType."); | 150 "Must use subclass of BaseElementType."); |
151 static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, | 151 static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, |
152 "Derived type requires stronger alignment."); | 152 "Derived type requires stronger alignment."); |
153 size_t allocSize = align(sizeof(DerivedElementType)); | 153 size_t allocSize = align(sizeof(DerivedElementType)); |
154 return *new (allocate(allocSize, WTF_HEAP_PROFILER_TYPE_NAME(DerivedElem
entType))) DerivedElementType(WTF::forward<Args>(args)...); | 154 return *new (allocate(allocSize, WTF_HEAP_PROFILER_TYPE_NAME(DerivedElem
entType))) DerivedElementType(std::forward<Args>(args)...); |
155 } | 155 } |
156 | 156 |
157 void removeLast() | 157 void removeLast() |
158 { | 158 { |
159 ASSERT(!isEmpty()); | 159 ASSERT(!isEmpty()); |
160 last().~BaseElementType(); | 160 last().~BaseElementType(); |
161 ContiguousContainerBase::removeLast(); | 161 ContiguousContainerBase::removeLast(); |
162 } | 162 } |
163 | 163 |
164 void clear() | 164 void clear() |
(...skipping 25 matching lines...) Expand all Loading... |
190 ASSERT(alignedSize % alignment == 0); | 190 ASSERT(alignedSize % alignment == 0); |
191 ASSERT(alignedSize >= size); | 191 ASSERT(alignedSize >= size); |
192 ASSERT(alignedSize < size + alignment); | 192 ASSERT(alignedSize < size + alignment); |
193 return alignedSize; | 193 return alignedSize; |
194 } | 194 } |
195 }; | 195 }; |
196 | 196 |
197 } // namespace blink | 197 } // namespace blink |
198 | 198 |
199 #endif // ContiguousContainer_h | 199 #endif // ContiguousContainer_h |
OLD | NEW |