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

Side by Side Diff: Source/platform/graphics/ListContainer.h

Issue 1207773003: Add ListContainer::swap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refactor for clairty 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 | Source/platform/graphics/ListContainerTest.cpp » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 ListContainer_h 5 #ifndef ListContainer_h
6 #define ListContainer_h 6 #define ListContainer_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "wtf/Forward.h" 9 #include "wtf/Forward.h"
10 #include "wtf/Noncopyable.h" 10 #include "wtf/Noncopyable.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 257 }
258 258
259 // Construct a new element on top of an existing one. 259 // Construct a new element on top of an existing one.
260 template <typename DerivedElementType> 260 template <typename DerivedElementType>
261 DerivedElementType* replaceExistingElement(Iterator at) 261 DerivedElementType* replaceExistingElement(Iterator at)
262 { 262 {
263 at->~BaseElementType(); 263 at->~BaseElementType();
264 return new (*at) DerivedElementType(); 264 return new (*at) DerivedElementType();
265 } 265 }
266 266
267 template <typename DerivedElementType>
268 void swap(ListContainer<DerivedElementType>& other)
269 {
270 m_data.swap(other.m_data);
271 }
272
267 // Appends a new item without copying. The original item will not be 273 // Appends a new item without copying. The original item will not be
268 // destructed and will be replaced with a new DerivedElementType. The 274 // destructed and will be replaced with a new DerivedElementType. The
269 // DerivedElementType does not have to match the moved type as a full block 275 // DerivedElementType does not have to match the moved type as a full block
270 // of memory will be moved (up to maxSizeForDerivedClass()). 276 // of memory will be moved (up to maxSizeForDerivedClass()).
271 template <typename DerivedElementType> 277 template <typename DerivedElementType>
272 void appendByMoving(DerivedElementType* item) 278 void appendByMoving(DerivedElementType* item)
273 { 279 {
274 size_t maxSize = maxSizeForDerivedClass(); 280 size_t maxSize = maxSizeForDerivedClass();
275 void* newItem = allocate(maxSize); 281 void* newItem = allocate(maxSize);
276 memcpy(newItem, static_cast<void*>(item), maxSize); 282 memcpy(newItem, static_cast<void*>(item), maxSize);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 explicit ConstReverseIterator(ListContainerBase::ConstReverseIterator ba seIterator) 435 explicit ConstReverseIterator(ListContainerBase::ConstReverseIterator ba seIterator)
430 : ListContainerBase::ConstReverseIterator(baseIterator) {} 436 : ListContainerBase::ConstReverseIterator(baseIterator) {}
431 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() co nst; 437 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() co nst;
432 friend ConstReverseIterator ListContainer<BaseElementType>::crend() cons t; 438 friend ConstReverseIterator ListContainer<BaseElementType>::crend() cons t;
433 }; 439 };
434 }; 440 };
435 441
436 } // namespace blink 442 } // namespace blink
437 443
438 #endif // ListContainer_h 444 #endif // ListContainer_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/graphics/ListContainerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698