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

Unified Diff: Source/platform/graphics/ListContainer.h

Issue 1205733002: Add ListContainer::appendByMoving (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Appease compiler overlords 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/graphics/ListContainer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/ListContainer.h
diff --git a/Source/platform/graphics/ListContainer.h b/Source/platform/graphics/ListContainer.h
index 5b317bb2c4523a18ef2021098ccabbd462f3d633..a63bffb698daf568c48aa1fe1cae414a7fefd40e 100644
--- a/Source/platform/graphics/ListContainer.h
+++ b/Source/platform/graphics/ListContainer.h
@@ -149,6 +149,8 @@ protected:
size_t size() const;
bool empty() const;
+ size_t maxSizeForDerivedClass() const;
+
// Unlike the ListContainer method, this one does not invoke element destructors.
void clear();
@@ -262,6 +264,20 @@ public:
return new (*at) DerivedElementType();
}
+ // Appends a new item without copying. The original item will not be
+ // destructed and will be replaced with a new DerivedElementType. The
+ // DerivedElementType does not have to match the moved type as a full block
+ // of memory will be moved (up to maxSizeForDerivedClass()).
+ template <typename DerivedElementType>
+ void appendByMoving(DerivedElementType* item)
+ {
+ size_t maxSize = maxSizeForDerivedClass();
+ void* newItem = allocate(maxSize);
+ memcpy(newItem, static_cast<void*>(item), maxSize);
+ // Construct a new element in-place so it can be destructed safely.
+ new (item) DerivedElementType;
+ }
+
using ListContainerBase::size;
using ListContainerBase::empty;
« no previous file with comments | « no previous file | Source/platform/graphics/ListContainer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698