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

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

Issue 1199343004: Add ListContainer::swap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor test for clarity 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_unittest.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/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 DerivedElementType(*source); 281 DerivedElementType(*source);
282 } 282 }
283 283
284 // Construct a new element on top of an existing one. 284 // Construct a new element on top of an existing one.
285 template <typename DerivedElementType> 285 template <typename DerivedElementType>
286 DerivedElementType* ReplaceExistingElement(Iterator at) { 286 DerivedElementType* ReplaceExistingElement(Iterator at) {
287 at->~BaseElementType(); 287 at->~BaseElementType();
288 return new (*at) DerivedElementType(); 288 return new (*at) DerivedElementType();
289 } 289 }
290 290
291 template <typename DerivedElementType>
292 void swap(ListContainer<DerivedElementType>& other) {
293 data_.swap(other.data_);
294 }
295
291 // Appends a new item without copying. The original item will not be 296 // Appends a new item without copying. The original item will not be
292 // destructed and will be replaced with a new DerivedElementType. The 297 // destructed and will be replaced with a new DerivedElementType. The
293 // DerivedElementType does not have to match the moved type as a full block 298 // DerivedElementType does not have to match the moved type as a full block
294 // of memory will be moved (up to MaxSizeForDerivedClass()). 299 // of memory will be moved (up to MaxSizeForDerivedClass()).
295 template <typename DerivedElementType> 300 template <typename DerivedElementType>
296 void AppendByMoving(DerivedElementType* item) { 301 void AppendByMoving(DerivedElementType* item) {
297 size_t max_size_for_derived_class = MaxSizeForDerivedClass(); 302 size_t max_size_for_derived_class = MaxSizeForDerivedClass();
298 void* new_item = Allocate(max_size_for_derived_class); 303 void* new_item = Allocate(max_size_for_derived_class);
299 memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class); 304 memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class);
300 // Construct a new element in-place so it can be destructed safely. 305 // Construct a new element in-place so it can be destructed safely.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 ListContainerBase::ConstReverseIterator base_iterator) 469 ListContainerBase::ConstReverseIterator base_iterator)
465 : ListContainerBase::ConstReverseIterator(base_iterator) {} 470 : ListContainerBase::ConstReverseIterator(base_iterator) {}
466 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; 471 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const;
467 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; 472 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const;
468 }; 473 };
469 }; 474 };
470 475
471 } // namespace cc 476 } // namespace cc
472 477
473 #endif // CC_BASE_LIST_CONTAINER_H_ 478 #endif // CC_BASE_LIST_CONTAINER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/base/list_container_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698