Chromium Code Reviews| Index: cc/quads/list_container.cc |
| diff --git a/cc/quads/list_container.cc b/cc/quads/list_container.cc |
| index b1501c0de862d50c4164849daa18a1709fcf32b7..3ad2f2e3ff26ebb8e0386f97b5357da9c151e13c 100644 |
| --- a/cc/quads/list_container.cc |
| +++ b/cc/quads/list_container.cc |
| @@ -87,8 +87,8 @@ class ListContainer<BaseElementType>::ListContainerCharAllocator { |
| size_(0), |
| list_count_(0), |
| last_list_(NULL) { |
| - DCHECK_NE(0u, element_count); |
| - AllocateNewList(element_count); |
| + AllocateNewList(element_count > 0 ? element_count |
| + : kDefaultNumElementTypesToReserve); |
| } |
| ~ListContainerCharAllocator() {} |
| @@ -281,72 +281,72 @@ template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::ConstReverseIterator |
| ListContainer<BaseElementType>::rbegin() const { |
| if (data_->IsEmpty()) |
| - return ConstReverseIterator(data_.get(), 0, NULL); |
| + return ConstReverseIterator(data_.get(), 0, NULL, 0); |
| size_t last_id = data_->list_count() - 1; |
| return ConstReverseIterator( |
| - data_.get(), last_id, data_->InnerListById(last_id)->LastElement()); |
| + data_.get(), last_id, data_->InnerListById(last_id)->LastElement(), 0); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::ConstReverseIterator |
| ListContainer<BaseElementType>::rend() const { |
| - return ConstReverseIterator(data_.get(), 0, NULL); |
| + return ConstReverseIterator(data_.get(), 0, NULL, size()); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::ReverseIterator |
| ListContainer<BaseElementType>::rbegin() { |
| if (data_->IsEmpty()) |
| - return ReverseIterator(data_.get(), 0, NULL); |
| + return ReverseIterator(data_.get(), 0, NULL, 0); |
| size_t last_id = data_->list_count() - 1; |
| return ReverseIterator( |
| - data_.get(), last_id, data_->InnerListById(last_id)->LastElement()); |
| + data_.get(), last_id, data_->InnerListById(last_id)->LastElement(), 0); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::ReverseIterator |
| ListContainer<BaseElementType>::rend() { |
| - return ReverseIterator(data_.get(), 0, NULL); |
| + return ReverseIterator(data_.get(), 0, NULL, size()); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::ConstIterator |
| ListContainer<BaseElementType>::begin() const { |
| if (data_->IsEmpty()) |
| - return ConstIterator(data_.get(), 0, NULL); |
| + return ConstIterator(data_.get(), 0, NULL, 0); |
| - return ConstIterator(data_.get(), 0, data_->InnerListById(0)->Begin()); |
| + return ConstIterator(data_.get(), 0, data_->InnerListById(0)->Begin(), 0); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::ConstIterator |
| ListContainer<BaseElementType>::end() const { |
| if (data_->IsEmpty()) |
| - return ConstIterator(data_.get(), 0, NULL); |
| + return ConstIterator(data_.get(), 0, NULL, size()); |
| size_t last_id = data_->list_count() - 1; |
| - return ConstIterator(data_.get(), last_id, NULL); |
| + return ConstIterator(data_.get(), last_id, NULL, size()); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::Iterator |
| ListContainer<BaseElementType>::begin() { |
| if (data_->IsEmpty()) |
| - return Iterator(data_.get(), 0, NULL); |
| + return Iterator(data_.get(), 0, NULL, 0); |
| - return Iterator(data_.get(), 0, data_->InnerListById(0)->Begin()); |
| + return Iterator(data_.get(), 0, data_->InnerListById(0)->Begin(), 0); |
| } |
| template <typename BaseElementType> |
| typename ListContainer<BaseElementType>::Iterator |
| ListContainer<BaseElementType>::end() { |
| if (data_->IsEmpty()) |
| - return Iterator(data_.get(), 0, NULL); |
| + return Iterator(data_.get(), 0, NULL, size()); |
| size_t last_id = data_->list_count() - 1; |
| - return Iterator(data_.get(), last_id, NULL); |
| + return Iterator(data_.get(), last_id, NULL, size()); |
| } |
| template <typename BaseElementType> |
| @@ -377,6 +377,7 @@ template <typename BaseElementType> |
| const BaseElementType* ListContainer<BaseElementType>::ElementAt( |
| size_t index) const { |
| DCHECK_LT(index, size()); |
| + size_t cache_index = index; |
|
danakj
2014/10/02 15:32:47
s/cache/original/
weiliangc
2014/10/02 22:01:39
Done.
|
| size_t list_index; |
| for (list_index = 0; list_index < data_->list_count(); ++list_index) { |
| size_t current_size = data_->InnerListById(list_index)->size; |
| @@ -386,12 +387,14 @@ const BaseElementType* ListContainer<BaseElementType>::ElementAt( |
| } |
| return &*ConstIterator(data_.get(), |
| list_index, |
| - data_->InnerListById(list_index)->ElementAt(index)); |
| + data_->InnerListById(list_index)->ElementAt(index), |
| + cache_index); |
| } |
| template <typename BaseElementType> |
| BaseElementType* ListContainer<BaseElementType>::ElementAt(size_t index) { |
| DCHECK_LT(index, size()); |
| + size_t cache_index = index; |
|
danakj
2014/10/02 15:32:47
same
weiliangc
2014/10/02 22:01:39
Done.
|
| size_t list_index; |
| for (list_index = 0; list_index < data_->list_count(); ++list_index) { |
| size_t current_size = data_->InnerListById(list_index)->size; |
| @@ -401,7 +404,8 @@ BaseElementType* ListContainer<BaseElementType>::ElementAt(size_t index) { |
| } |
| return &*Iterator(data_.get(), |
| list_index, |
| - data_->InnerListById(list_index)->ElementAt(index)); |
| + data_->InnerListById(list_index)->ElementAt(index), |
| + cache_index); |
| } |
| template <typename BaseElementType> |
| @@ -442,8 +446,10 @@ template <typename BaseElementType> |
| ListContainer<BaseElementType>::Iterator::Iterator( |
| ListContainerCharAllocator* container, |
| size_t vector_ind, |
| - char* item_iter) |
| - : PositionInListContainerCharAllocator(container, vector_ind, item_iter) { |
| + char* item_iter, |
| + size_t index) |
| + : PositionInListContainerCharAllocator(container, vector_ind, item_iter), |
| + index_(index) { |
| } |
| template <typename BaseElementType> |
| @@ -474,23 +480,31 @@ typename ListContainer<BaseElementType>::Iterator |
| ListContainer<BaseElementType>::Iterator:: |
| operator++() { |
| this->Increment(); |
| + ++index_; |
| return *this; |
| } |
| +template <typename BaseElementType> |
| +size_t ListContainer<BaseElementType>::Iterator::index() const { |
| + return index_; |
| +} |
| + |
| // ListContainer::ConstIterator |
| ///////////////////////////////////////////////// |
| template <typename BaseElementType> |
| ListContainer<BaseElementType>::ConstIterator::ConstIterator( |
| const typename ListContainer<BaseElementType>::Iterator& other) |
| - : PositionInListContainerCharAllocator(other) { |
| + : PositionInListContainerCharAllocator(other), index_(other.index()) { |
| } |
| template <typename BaseElementType> |
| ListContainer<BaseElementType>::ConstIterator::ConstIterator( |
| ListContainerCharAllocator* container, |
| size_t vector_ind, |
| - char* item_iter) |
| - : PositionInListContainerCharAllocator(container, vector_ind, item_iter) { |
| + char* item_iter, |
| + size_t index) |
| + : PositionInListContainerCharAllocator(container, vector_ind, item_iter), |
| + index_(index) { |
| } |
| template <typename BaseElementType> |
| @@ -523,17 +537,25 @@ typename ListContainer<BaseElementType>::ConstIterator |
| ListContainer<BaseElementType>::ConstIterator:: |
| operator++() { |
| this->Increment(); |
| + ++index_; |
| return *this; |
| } |
| +template <typename BaseElementType> |
| +size_t ListContainer<BaseElementType>::ConstIterator::index() const { |
| + return index_; |
| +} |
| + |
| // ListContainer::ReverseIterator |
| ///////////////////////////////////////////////// |
| template <typename BaseElementType> |
| ListContainer<BaseElementType>::ReverseIterator::ReverseIterator( |
| ListContainerCharAllocator* container, |
| size_t vector_ind, |
| - char* item_iter) |
| - : PositionInListContainerCharAllocator(container, vector_ind, item_iter) { |
| + char* item_iter, |
| + size_t index) |
| + : PositionInListContainerCharAllocator(container, vector_ind, item_iter), |
| + index_(index) { |
| } |
| template <typename BaseElementType> |
| @@ -566,23 +588,31 @@ typename ListContainer<BaseElementType>::ReverseIterator |
| ListContainer<BaseElementType>::ReverseIterator:: |
| operator++() { |
| this->ReverseIncrement(); |
| + ++index_; |
| return *this; |
| } |
| +template <typename BaseElementType> |
| +size_t ListContainer<BaseElementType>::ReverseIterator::index() const { |
| + return index_; |
| +} |
| + |
| // ListContainer::ConstReverseIterator |
| ///////////////////////////////////////////////// |
| template <typename BaseElementType> |
| ListContainer<BaseElementType>::ConstReverseIterator::ConstReverseIterator( |
| const typename ListContainer<BaseElementType>::ReverseIterator& other) |
| - : PositionInListContainerCharAllocator(other) { |
| + : PositionInListContainerCharAllocator(other), index_(other.index()) { |
| } |
| template <typename BaseElementType> |
| ListContainer<BaseElementType>::ConstReverseIterator::ConstReverseIterator( |
| ListContainerCharAllocator* container, |
| size_t vector_ind, |
| - char* item_iter) |
| - : PositionInListContainerCharAllocator(container, vector_ind, item_iter) { |
| + char* item_iter, |
| + size_t index) |
| + : PositionInListContainerCharAllocator(container, vector_ind, item_iter), |
| + index_(index) { |
| } |
| template <typename BaseElementType> |
| @@ -615,9 +645,15 @@ typename ListContainer<BaseElementType>::ConstReverseIterator |
| ListContainer<BaseElementType>::ConstReverseIterator:: |
| operator++() { |
| this->ReverseIncrement(); |
| + ++index_; |
| return *this; |
| } |
| +template <typename BaseElementType> |
| +size_t ListContainer<BaseElementType>::ConstReverseIterator::index() const { |
| + return index_; |
| +} |
| + |
| template class ListContainer<SharedQuadState>; |
| template class ListContainer<DrawQuad>; |