Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: cc/base/list_container.cc

Issue 1226503006: cc: More consistent reasoning about display list memory usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: capacity unit test Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "cc/base/list_container.h" 5 #include "cc/base/list_container.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "cc/base/scoped_ptr_vector.h" 10 #include "cc/base/scoped_ptr_vector.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return last_list_->AddElement(); 113 return last_list_->AddElement();
114 } 114 }
115 115
116 size_t element_size() const { return element_size_; } 116 size_t element_size() const { return element_size_; }
117 size_t list_count() const { return storage_.size(); } 117 size_t list_count() const { return storage_.size(); }
118 size_t size() const { return size_; } 118 size_t size() const { return size_; }
119 bool IsEmpty() const { return size() == 0; } 119 bool IsEmpty() const { return size() == 0; }
120 120
121 size_t Capacity() const { 121 size_t Capacity() const {
122 size_t capacity_sum = 0; 122 size_t capacity_sum = 0;
123 for (ScopedPtrVector<InnerList>::const_iterator iter = storage_.begin(); 123 for (const auto& inner_list : storage_)
124 iter != storage_.end(); ++iter) { 124 capacity_sum += inner_list->capacity;
125 capacity_sum += (*iter)->capacity;
126 }
127 return capacity_sum; 125 return capacity_sum;
128 } 126 }
129 127
130 void Clear() { 128 void Clear() {
131 // Remove all except for the first InnerList. 129 // Remove all except for the first InnerList.
132 DCHECK(!storage_.empty()); 130 DCHECK(!storage_.empty());
133 storage_.erase(storage_.begin() + 1, storage_.end()); 131 storage_.erase(storage_.begin() + 1, storage_.end());
134 last_list_index_ = 0; 132 last_list_index_ = 0;
135 last_list_ = storage_[0]; 133 last_list_ = storage_[0];
136 last_list_->size = 0; 134 last_list_->size = 0;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 416 }
419 417
420 bool ListContainerBase::empty() const { 418 bool ListContainerBase::empty() const {
421 return data_->IsEmpty(); 419 return data_->IsEmpty();
422 } 420 }
423 421
424 size_t ListContainerBase::MaxSizeForDerivedClass() const { 422 size_t ListContainerBase::MaxSizeForDerivedClass() const {
425 return data_->element_size(); 423 return data_->element_size();
426 } 424 }
427 425
426 size_t ListContainerBase::GetCapacityInBytes() const {
427 return data_->Capacity() * data_->element_size();
428 }
429
428 void ListContainerBase::clear() { 430 void ListContainerBase::clear() {
429 data_->Clear(); 431 data_->Clear();
430 } 432 }
431 433
432 size_t ListContainerBase::AvailableSizeWithoutAnotherAllocationForTesting() 434 size_t ListContainerBase::AvailableSizeWithoutAnotherAllocationForTesting()
433 const { 435 const {
434 return data_->NumAvailableElementsInLastList(); 436 return data_->NumAvailableElementsInLastList();
435 } 437 }
436 438
437 // ListContainerBase::Iterator 439 // ListContainerBase::Iterator
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 511 }
510 512
511 ListContainerBase::ConstReverseIterator::~ConstReverseIterator() { 513 ListContainerBase::ConstReverseIterator::~ConstReverseIterator() {
512 } 514 }
513 515
514 size_t ListContainerBase::ConstReverseIterator::index() const { 516 size_t ListContainerBase::ConstReverseIterator::index() const {
515 return index_; 517 return index_;
516 } 518 }
517 519
518 } // namespace cc 520 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698