Chromium Code Reviews| Index: cc/base/list_container.h |
| diff --git a/cc/base/list_container.h b/cc/base/list_container.h |
| index 0c3772b82fdb9acbf27e731f42679025835f29ac..cb31901cbaf348f5c2949c0db1662149c6618741 100644 |
| --- a/cc/base/list_container.h |
| +++ b/cc/base/list_container.h |
| @@ -161,6 +161,8 @@ class CC_EXPORT ListContainerBase { |
| size_t size() const; |
| bool empty() const; |
| + size_t MaxSizeForDerivedClass() const; |
| + |
| // Unlike the ListContainer method, this one does not invoke element |
| // destructors. |
| void clear(); |
| @@ -283,6 +285,15 @@ class ListContainer : public ListContainerBase { |
| at->~BaseElementType(); |
| return new (*at) DerivedElementType(); |
| } |
| + // 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
|
| + // 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
|
| + template <typename DerivedElementType> |
| + void AppendByMoving(DerivedElementType* other_item) { |
| + size_t max_size_for_derived_class = MaxSizeForDerivedClass(); |
| + void* new_item = Allocate(max_size_for_derived_class); |
| + 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
|
| + 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
|
| + } |
| using ListContainerBase::size; |
| using ListContainerBase::empty; |