| 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" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 void swap(ContiguousContainer& other) { ContiguousContainerBase::swap(other)
; } | 170 void swap(ContiguousContainer& other) { ContiguousContainerBase::swap(other)
; } |
| 171 | 171 |
| 172 // Appends a new element using memcpy, then default-constructs a base | 172 // Appends a new element using memcpy, then default-constructs a base |
| 173 // element in its place. Use with care. | 173 // element in its place. Use with care. |
| 174 BaseElementType& appendByMoving(BaseElementType& item, size_t size) | 174 BaseElementType& appendByMoving(BaseElementType& item, size_t size) |
| 175 { | 175 { |
| 176 ASSERT(size >= sizeof(BaseElementType)); | 176 ASSERT(size >= sizeof(BaseElementType)); |
| 177 void* newItem = allocate(size); | 177 void* newItem = allocate(size); |
| 178 memcpy(newItem, static_cast<void*>(&item), size); | 178 memcpy(newItem, static_cast<void*>(&item), size); |
| 179 new (&item) BaseElementType; | 179 new (&item) BaseElementType( |
| 180 #ifndef NDEBUG |
| 181 item.asDebugString() |
| 182 #endif |
| 183 ); |
| 180 return *static_cast<BaseElementType*>(newItem); | 184 return *static_cast<BaseElementType*>(newItem); |
| 181 } | 185 } |
| 182 | 186 |
| 183 private: | 187 private: |
| 184 static size_t align(size_t size) | 188 static size_t align(size_t size) |
| 185 { | 189 { |
| 186 size_t alignedSize = alignment * ((size + alignment - 1) / alignment); | 190 size_t alignedSize = alignment * ((size + alignment - 1) / alignment); |
| 187 ASSERT(alignedSize % alignment == 0); | 191 ASSERT(alignedSize % alignment == 0); |
| 188 ASSERT(alignedSize >= size); | 192 ASSERT(alignedSize >= size); |
| 189 ASSERT(alignedSize < size + alignment); | 193 ASSERT(alignedSize < size + alignment); |
| 190 return alignedSize; | 194 return alignedSize; |
| 191 } | 195 } |
| 192 }; | 196 }; |
| 193 | 197 |
| 194 } // namespace blink | 198 } // namespace blink |
| 195 | 199 |
| 196 #endif // ContiguousContainer_h | 200 #endif // ContiguousContainer_h |
| OLD | NEW |