| 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 ListContainer_h | 5 #ifndef ListContainer_h |
| 6 #define ListContainer_h | 6 #define ListContainer_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "wtf/Forward.h" | 9 #include "wtf/Forward.h" |
| 10 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 ConstIterator cend() const; | 142 ConstIterator cend() const; |
| 143 Iterator begin(); | 143 Iterator begin(); |
| 144 Iterator end(); | 144 Iterator end(); |
| 145 | 145 |
| 146 Iterator iteratorAt(size_t index); | 146 Iterator iteratorAt(size_t index); |
| 147 ConstIterator iteratorAt(size_t index) const; | 147 ConstIterator iteratorAt(size_t index) const; |
| 148 | 148 |
| 149 size_t size() const; | 149 size_t size() const; |
| 150 bool empty() const; | 150 bool empty() const; |
| 151 | 151 |
| 152 size_t maxSizeForDerivedClass() const; |
| 153 |
| 152 // Unlike the ListContainer method, this one does not invoke element destruc
tors. | 154 // Unlike the ListContainer method, this one does not invoke element destruc
tors. |
| 153 void clear(); | 155 void clear(); |
| 154 | 156 |
| 155 size_t availableSizeWithoutAnotherAllocationForTesting() const; | 157 size_t availableSizeWithoutAnotherAllocationForTesting() const; |
| 156 | 158 |
| 157 // Hands out memory location for an element at the end of data structure. | 159 // Hands out memory location for an element at the end of data structure. |
| 158 void* allocate(size_t sizeOfActualElementInBytes); | 160 void* allocate(size_t sizeOfActualElementInBytes); |
| 159 | 161 |
| 160 OwnPtr<ListContainerCharAllocator> m_data; | 162 OwnPtr<ListContainerCharAllocator> m_data; |
| 161 }; | 163 }; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 } | 257 } |
| 256 | 258 |
| 257 // Construct a new element on top of an existing one. | 259 // Construct a new element on top of an existing one. |
| 258 template <typename DerivedElementType> | 260 template <typename DerivedElementType> |
| 259 DerivedElementType* replaceExistingElement(Iterator at) | 261 DerivedElementType* replaceExistingElement(Iterator at) |
| 260 { | 262 { |
| 261 at->~BaseElementType(); | 263 at->~BaseElementType(); |
| 262 return new (*at) DerivedElementType(); | 264 return new (*at) DerivedElementType(); |
| 263 } | 265 } |
| 264 | 266 |
| 267 // Appends a new item without copying. The original item will not be |
| 268 // destructed and will be replaced with a new DerivedElementType. The |
| 269 // DerivedElementType does not have to match the moved type as a full block |
| 270 // of memory will be moved (up to maxSizeForDerivedClass()). |
| 271 template <typename DerivedElementType> |
| 272 void appendByMoving(DerivedElementType* item) |
| 273 { |
| 274 size_t maxSize = maxSizeForDerivedClass(); |
| 275 void* newItem = allocate(maxSize); |
| 276 memcpy(newItem, static_cast<void*>(item), maxSize); |
| 277 // Construct a new element in-place so it can be destructed safely. |
| 278 new (item) DerivedElementType; |
| 279 } |
| 280 |
| 265 using ListContainerBase::size; | 281 using ListContainerBase::size; |
| 266 using ListContainerBase::empty; | 282 using ListContainerBase::empty; |
| 267 | 283 |
| 268 void clear() | 284 void clear() |
| 269 { | 285 { |
| 270 for (Iterator i = begin(); i != end(); ++i) | 286 for (Iterator i = begin(); i != end(); ++i) |
| 271 i->~BaseElementType(); | 287 i->~BaseElementType(); |
| 272 ListContainerBase::clear(); | 288 ListContainerBase::clear(); |
| 273 } | 289 } |
| 274 | 290 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 explicit ConstReverseIterator(ListContainerBase::ConstReverseIterator ba
seIterator) | 429 explicit ConstReverseIterator(ListContainerBase::ConstReverseIterator ba
seIterator) |
| 414 : ListContainerBase::ConstReverseIterator(baseIterator) {} | 430 : ListContainerBase::ConstReverseIterator(baseIterator) {} |
| 415 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() co
nst; | 431 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() co
nst; |
| 416 friend ConstReverseIterator ListContainer<BaseElementType>::crend() cons
t; | 432 friend ConstReverseIterator ListContainer<BaseElementType>::crend() cons
t; |
| 417 }; | 433 }; |
| 418 }; | 434 }; |
| 419 | 435 |
| 420 } // namespace blink | 436 } // namespace blink |
| 421 | 437 |
| 422 #endif // ListContainer_h | 438 #endif // ListContainer_h |
| OLD | NEW |