| 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/Compiler.h" | 10 #include "wtf/Compiler.h" |
| 11 #include "wtf/Noncopyable.h" | 11 #include "wtf/Noncopyable.h" |
| 12 #include "wtf/OwnPtr.h" | 12 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/TypeTraits.h" | 13 #include "wtf/TypeTraits.h" |
| 14 #include "wtf/Utility.h" | |
| 15 #include "wtf/Vector.h" | 14 #include "wtf/Vector.h" |
| 16 #include <cstddef> | 15 #include <cstddef> |
| 17 #include <iterator> | 16 #include <iterator> |
| 17 #include <utility> |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 // ContiguousContainer is a container which stores a list of heterogeneous | 21 // ContiguousContainer is a container which stores a list of heterogeneous |
| 22 // objects (in particular, of varying sizes), packed next to one another in | 22 // objects (in particular, of varying sizes), packed next to one another in |
| 23 // memory. Objects are never relocated, so it is safe to store pointers to them | 23 // memory. Objects are never relocated, so it is safe to store pointers to them |
| 24 // for the lifetime of the container (unless the object is removed). | 24 // for the lifetime of the container (unless the object is removed). |
| 25 // | 25 // |
| 26 // Memory is allocated in a series of buffers (with exponential growth). When an | 26 // Memory is allocated in a series of buffers (with exponential growth). When an |
| 27 // object is allocated, it is given only the space it requires (possibly with | 27 // object is allocated, it is given only the space it requires (possibly with |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 const BaseElementType& operator[](size_t index) const { return *(begin() + i
ndex); } | 141 const BaseElementType& operator[](size_t index) const { return *(begin() + i
ndex); } |
| 142 | 142 |
| 143 template <class DerivedElementType, typename... Args> | 143 template <class DerivedElementType, typename... Args> |
| 144 DerivedElementType& allocateAndConstruct(Args&&... args) | 144 DerivedElementType& allocateAndConstruct(Args&&... args) |
| 145 { | 145 { |
| 146 static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::valu
e, | 146 static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::valu
e, |
| 147 "Must use subclass of BaseElementType."); | 147 "Must use subclass of BaseElementType."); |
| 148 static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, | 148 static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, |
| 149 "Derived type requires stronger alignment."); | 149 "Derived type requires stronger alignment."); |
| 150 size_t allocSize = align(sizeof(DerivedElementType)); | 150 size_t allocSize = align(sizeof(DerivedElementType)); |
| 151 return *new (allocate(allocSize)) DerivedElementType(WTF::forward<Args>(
args)...); | 151 return *new (allocate(allocSize)) DerivedElementType(std::forward<Args>(
args)...); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void removeLast() | 154 void removeLast() |
| 155 { | 155 { |
| 156 ASSERT(!isEmpty()); | 156 ASSERT(!isEmpty()); |
| 157 last().~BaseElementType(); | 157 last().~BaseElementType(); |
| 158 ContiguousContainerBase::removeLast(); | 158 ContiguousContainerBase::removeLast(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void clear() | 161 void clear() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 187 ASSERT(alignedSize % alignment == 0); | 187 ASSERT(alignedSize % alignment == 0); |
| 188 ASSERT(alignedSize >= size); | 188 ASSERT(alignedSize >= size); |
| 189 ASSERT(alignedSize < size + alignment); | 189 ASSERT(alignedSize < size + alignment); |
| 190 return alignedSize; | 190 return alignedSize; |
| 191 } | 191 } |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 } // namespace blink | 194 } // namespace blink |
| 195 | 195 |
| 196 #endif // ContiguousContainer_h | 196 #endif // ContiguousContainer_h |
| OLD | NEW |