Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CC_BASE_LIST_CONTAINER_H_ | 5 #ifndef CC_BASE_LIST_CONTAINER_H_ |
| 6 #define CC_BASE_LIST_CONTAINER_H_ | 6 #define CC_BASE_LIST_CONTAINER_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 ConstIterator cend() const; | 154 ConstIterator cend() const; |
| 155 Iterator begin(); | 155 Iterator begin(); |
| 156 Iterator end(); | 156 Iterator end(); |
| 157 | 157 |
| 158 Iterator IteratorAt(size_t index); | 158 Iterator IteratorAt(size_t index); |
| 159 ConstIterator IteratorAt(size_t index) const; | 159 ConstIterator IteratorAt(size_t index) const; |
| 160 | 160 |
| 161 size_t size() const; | 161 size_t size() const; |
| 162 bool empty() const; | 162 bool empty() const; |
| 163 | 163 |
| 164 size_t MaxSizeForDerivedClass() const; | |
| 165 | |
| 164 // Unlike the ListContainer method, this one does not invoke element | 166 // Unlike the ListContainer method, this one does not invoke element |
| 165 // destructors. | 167 // destructors. |
| 166 void clear(); | 168 void clear(); |
| 167 | 169 |
| 168 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; | 170 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; |
| 169 | 171 |
| 170 // Hands out memory location for an element at the end of data structure. | 172 // Hands out memory location for an element at the end of data structure. |
| 171 void* Allocate(size_t size_of_actual_element_in_bytes); | 173 void* Allocate(size_t size_of_actual_element_in_bytes); |
| 172 | 174 |
| 173 scoped_ptr<ListContainerCharAllocator> data_; | 175 scoped_ptr<ListContainerCharAllocator> data_; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 DerivedElementType* AllocateAndCopyFrom(const DerivedElementType* source) { | 278 DerivedElementType* AllocateAndCopyFrom(const DerivedElementType* source) { |
| 277 return new (Allocate(sizeof(DerivedElementType))) | 279 return new (Allocate(sizeof(DerivedElementType))) |
| 278 DerivedElementType(*source); | 280 DerivedElementType(*source); |
| 279 } | 281 } |
| 280 // Construct a new element on top of an existing one. | 282 // Construct a new element on top of an existing one. |
| 281 template <typename DerivedElementType> | 283 template <typename DerivedElementType> |
| 282 DerivedElementType* ReplaceExistingElement(Iterator at) { | 284 DerivedElementType* ReplaceExistingElement(Iterator at) { |
| 283 at->~BaseElementType(); | 285 at->~BaseElementType(); |
| 284 return new (*at) DerivedElementType(); | 286 return new (*at) DerivedElementType(); |
| 285 } | 287 } |
| 288 // Appends a new item without copying. The original item will not be | |
|
danakj
2015/06/23 20:01:12
nit: add whitespace above this
pdr.
2015/06/23 21:42:42
Done. I also added spaces to the 3 others above (R
| |
| 289 // destructed and will be replaced with a new DerivedElementType. | |
|
danakj
2015/06/23 20:01:12
Can you also mention that the DerivedElementType d
pdr.
2015/06/23 21:42:41
Done.
Comment now reads:
// Appends a new item wi
| |
| 290 template <typename DerivedElementType> | |
| 291 void AppendByMoving(DerivedElementType* other_item) { | |
| 292 size_t max_size_for_derived_class = MaxSizeForDerivedClass(); | |
| 293 void* new_item = Allocate(max_size_for_derived_class); | |
| 294 memcpy(new_item, (void*)other_item, max_size_for_derived_class); | |
|
danakj
2015/06/23 20:01:12
why do you have to (void*)? and if so, use static_
pdr.
2015/06/23 21:42:41
The c-style cats have been replaced with static_ca
| |
| 295 new (other_item) DerivedElementType; | |
|
danakj
2015/06/23 20:01:12
can you leave a comment explaining this is overwri
pdr.
2015/06/23 21:42:42
Done. The comment now reads:
// Construct a new el
| |
| 296 } | |
| 286 | 297 |
| 287 using ListContainerBase::size; | 298 using ListContainerBase::size; |
| 288 using ListContainerBase::empty; | 299 using ListContainerBase::empty; |
| 289 | 300 |
| 290 void clear() { | 301 void clear() { |
| 291 for (Iterator i = begin(); i != end(); ++i) { | 302 for (Iterator i = begin(); i != end(); ++i) { |
| 292 i->~BaseElementType(); | 303 i->~BaseElementType(); |
| 293 } | 304 } |
| 294 ListContainerBase::clear(); | 305 ListContainerBase::clear(); |
| 295 } | 306 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 ListContainerBase::ConstReverseIterator base_iterator) | 458 ListContainerBase::ConstReverseIterator base_iterator) |
| 448 : ListContainerBase::ConstReverseIterator(base_iterator) {} | 459 : ListContainerBase::ConstReverseIterator(base_iterator) {} |
| 449 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; | 460 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; |
| 450 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; | 461 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; |
| 451 }; | 462 }; |
| 452 }; | 463 }; |
| 453 | 464 |
| 454 } // namespace cc | 465 } // namespace cc |
| 455 | 466 |
| 456 #endif // CC_BASE_LIST_CONTAINER_H_ | 467 #endif // CC_BASE_LIST_CONTAINER_H_ |
| OLD | NEW |