Chromium Code Reviews| Index: cc/base/list_container.cc |
| diff --git a/cc/base/list_container.cc b/cc/base/list_container.cc |
| index df21a5b2e486a144736e9c817c66aa30d5acccda..e91a45bf84b236abf104fb70f9141f182e9ce8c4 100644 |
| --- a/cc/base/list_container.cc |
| +++ b/cc/base/list_container.cc |
| @@ -53,6 +53,7 @@ class ListContainerBase::ListContainerCharAllocator { |
| --capacity; |
| } |
| + bool IsEmpty() const { return !size; } |
| bool IsFull() { return capacity == size; } |
| size_t NumElementsAvailable() const { return capacity - size; } |
| @@ -62,6 +63,11 @@ class ListContainerBase::ListContainerCharAllocator { |
| return LastElement(); |
| } |
| + void RemoveLast() { |
| + DCHECK(!IsEmpty()); |
| + --size; |
| + } |
| + |
| char* Begin() const { return data.get(); } |
| char* End() const { return data.get() + size * step; } |
| char* LastElement() const { return data.get() + (size - 1) * step; } |
| @@ -121,6 +127,14 @@ class ListContainerBase::ListContainerCharAllocator { |
| AllocateNewList(initial_allocation_size); |
| } |
| + void RemoveLast() { |
| + DCHECK(!IsEmpty()); |
| + last_list_->RemoveLast(); |
| + if (last_list_->IsEmpty()) |
| + DeallocateLastList(); |
|
danakj
2015/06/02 20:04:32
Is it possible to avoid this deallocate and just l
|
| + --size_; |
| + } |
| + |
| void Erase(PositionInListContainerCharAllocator position) { |
| DCHECK_EQ(this, position.ptr_to_container); |
| storage_[position.vector_index]->Erase(position.item_iterator); |
| @@ -170,6 +184,15 @@ class ListContainerBase::ListContainerCharAllocator { |
| } |
| private: |
| + void DeallocateLastList() { |
| + // Don't deallocate the only list; we always expect there to be one. |
| + if (list_count_ <= 1) |
| + return; |
| + --list_count_; |
| + storage_.pop_back(); |
| + last_list_ = list_count_ ? storage_.back() : nullptr; |
| + } |
| + |
| ScopedPtrVector<InnerList> storage_; |
| const size_t element_size_; |
| size_t size_; |
| @@ -275,6 +298,10 @@ ListContainerBase::ListContainerBase(size_t max_size_for_derived_class, |
| ListContainerBase::~ListContainerBase() { |
| } |
| +void ListContainerBase::RemoveLast() { |
| + data_->RemoveLast(); |
| +} |
| + |
| void ListContainerBase::EraseAndInvalidateAllPointers( |
| ListContainerBase::Iterator position) { |
| data_->Erase(position); |