| Index: cc/base/list_container.h
|
| diff --git a/cc/base/list_container.h b/cc/base/list_container.h
|
| index 0c3772b82fdb9acbf27e731f42679025835f29ac..5463ca2066873bef445acb6a66bcbf084db2bb37 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();
|
| @@ -270,6 +272,7 @@ class ListContainer : public ListContainerBase {
|
| DerivedElementType* AllocateAndConstruct() {
|
| return new (Allocate(sizeof(DerivedElementType))) DerivedElementType;
|
| }
|
| +
|
| // Take in derived element type and copy construct it at location generated by
|
| // Allocate().
|
| template <typename DerivedElementType>
|
| @@ -277,6 +280,7 @@ class ListContainer : public ListContainerBase {
|
| return new (Allocate(sizeof(DerivedElementType)))
|
| DerivedElementType(*source);
|
| }
|
| +
|
| // Construct a new element on top of an existing one.
|
| template <typename DerivedElementType>
|
| DerivedElementType* ReplaceExistingElement(Iterator at) {
|
| @@ -284,6 +288,19 @@ class ListContainer : public ListContainerBase {
|
| return new (*at) DerivedElementType();
|
| }
|
|
|
| + // Appends a new item without copying. The original item will not be
|
| + // destructed and will be replaced with a new DerivedElementType. The
|
| + // DerivedElementType does not have to match the moved type as a full block
|
| + // of memory will be moved (up to MaxSizeForDerivedClass()).
|
| + template <typename DerivedElementType>
|
| + void AppendByMoving(DerivedElementType* item) {
|
| + size_t max_size_for_derived_class = MaxSizeForDerivedClass();
|
| + void* new_item = Allocate(max_size_for_derived_class);
|
| + memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class);
|
| + // Construct a new element in-place so it can be destructed safely.
|
| + new (item) DerivedElementType;
|
| + }
|
| +
|
| using ListContainerBase::size;
|
| using ListContainerBase::empty;
|
|
|
|
|