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

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

Issue 1163803003: cc: Implement RemoveLast for DisplayItemList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: danakj comments Created 5 years, 6 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
« no previous file with comments | « no previous file | cc/base/list_container.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CC_BASE_LIST_CONTAINER_H_ 5 #ifndef CC_BASE_LIST_CONTAINER_H_
6 #define CC_BASE_LIST_CONTAINER_H_ 6 #define CC_BASE_LIST_CONTAINER_H_
7 7
8 #include "base/logging.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h" 11 #include "cc/base/cc_export.h"
11 12
12 namespace cc { 13 namespace cc {
13 14
14 // ListContainer is a container type that handles allocating contiguous memory 15 // ListContainer is a container type that handles allocating contiguous memory
15 // for new elements and traversing through elements with either iterator or 16 // for new elements and traversing through elements with either iterator or
16 // reverse iterator. Since this container hands out raw pointers of its 17 // reverse iterator. Since this container hands out raw pointers of its
17 // elements, it is very important that this container never reallocate its 18 // elements, it is very important that this container never reallocate its
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 size_t index() const; 135 size_t index() const;
135 136
136 protected: 137 protected:
137 // This is used to track how many increment has happened since rbegin(). It 138 // This is used to track how many increment has happened since rbegin(). It
138 // is used to avoid double increment at places an index reference is 139 // is used to avoid double increment at places an index reference is
139 // needed. For reverse iterator this means rbegin() corresponds to index 0 140 // needed. For reverse iterator this means rbegin() corresponds to index 0
140 // and rend() corresponds to index |size|. 141 // and rend() corresponds to index |size|.
141 size_t index_; 142 size_t index_;
142 }; 143 };
143 144
144 // Unlike the ListContainer method, this one does not invoke element 145 // Unlike the ListContainer methods, these do not invoke element destructors.
145 // destructors. 146 void RemoveLast();
146 void EraseAndInvalidateAllPointers(Iterator position); 147 void EraseAndInvalidateAllPointers(Iterator position);
147 148
148 ConstReverseIterator crbegin() const; 149 ConstReverseIterator crbegin() const;
149 ConstReverseIterator crend() const; 150 ConstReverseIterator crend() const;
150 ReverseIterator rbegin(); 151 ReverseIterator rbegin();
151 ReverseIterator rend(); 152 ReverseIterator rend();
152 ConstIterator cbegin() const; 153 ConstIterator cbegin() const;
153 ConstIterator cend() const; 154 ConstIterator cend() const;
154 Iterator begin(); 155 Iterator begin();
155 Iterator end(); 156 Iterator end();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 for (Iterator i = begin(); i != end(); ++i) { 203 for (Iterator i = begin(); i != end(); ++i) {
203 i->~BaseElementType(); 204 i->~BaseElementType();
204 } 205 }
205 } 206 }
206 207
207 class Iterator; 208 class Iterator;
208 class ConstIterator; 209 class ConstIterator;
209 class ReverseIterator; 210 class ReverseIterator;
210 class ConstReverseIterator; 211 class ConstReverseIterator;
211 212
213 // Removes the last element of the list and makes its space available for
214 // allocation.
215 void RemoveLast() {
216 DCHECK(!empty());
217 back()->~BaseElementType();
218 ListContainerBase::RemoveLast();
219 }
220
212 // When called, all raw pointers that have been handed out are no longer 221 // When called, all raw pointers that have been handed out are no longer
213 // valid. Use with caution. 222 // valid. Use with caution.
214 // This function does not deallocate memory. 223 // This function does not deallocate memory.
215 void EraseAndInvalidateAllPointers(Iterator position) { 224 void EraseAndInvalidateAllPointers(Iterator position) {
216 BaseElementType* item = *position; 225 BaseElementType* item = *position;
217 item->~BaseElementType(); 226 item->~BaseElementType();
218 ListContainerBase::EraseAndInvalidateAllPointers(position); 227 ListContainerBase::EraseAndInvalidateAllPointers(position);
219 } 228 }
220 229
221 ConstReverseIterator crbegin() const { 230 ConstReverseIterator crbegin() const {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 ListContainerBase::ConstReverseIterator base_iterator) 447 ListContainerBase::ConstReverseIterator base_iterator)
439 : ListContainerBase::ConstReverseIterator(base_iterator) {} 448 : ListContainerBase::ConstReverseIterator(base_iterator) {}
440 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; 449 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const;
441 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; 450 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const;
442 }; 451 };
443 }; 452 };
444 453
445 } // namespace cc 454 } // namespace cc
446 455
447 #endif // CC_BASE_LIST_CONTAINER_H_ 456 #endif // CC_BASE_LIST_CONTAINER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/base/list_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698