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

Unified Diff: cc/base/list_container.h

Issue 1202153002: Add ListContainer::AppendByMoving (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Appease the compiler overlords with the gift of a type literal suffix 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 | cc/base/list_container.cc » ('j') | cc/base/list_container_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/list_container.h
diff --git a/cc/base/list_container.h b/cc/base/list_container.h
index 0c3772b82fdb9acbf27e731f42679025835f29ac..cb31901cbaf348f5c2949c0db1662149c6618741 100644
--- a/cc/base/list_container.h
+++ b/cc/base/list_container.h
@@ -161,6 +161,8 @@ class CC_EXPORT ListContainerBase {
size_t size() const;
bool empty() const;
+ size_t MaxSizeForDerivedClass() const;
+
// Unlike the ListContainer method, this one does not invoke element
// destructors.
void clear();
@@ -283,6 +285,15 @@ class ListContainer : public ListContainerBase {
at->~BaseElementType();
return new (*at) DerivedElementType();
}
+ // Appends a new item without copying. The original item will not be
danakj 2015/06/23 20:01:12 nit: add whitespace above this
pdr. 2015/06/23 21:42:42 Done. I also added spaces to the 3 others above (R
+ // destructed and will be replaced with a new DerivedElementType.
danakj 2015/06/23 20:01:12 Can you also mention that the DerivedElementType d
pdr. 2015/06/23 21:42:41 Done. Comment now reads: // Appends a new item wi
+ template <typename DerivedElementType>
+ void AppendByMoving(DerivedElementType* other_item) {
+ size_t max_size_for_derived_class = MaxSizeForDerivedClass();
+ void* new_item = Allocate(max_size_for_derived_class);
+ memcpy(new_item, (void*)other_item, max_size_for_derived_class);
danakj 2015/06/23 20:01:12 why do you have to (void*)? and if so, use static_
pdr. 2015/06/23 21:42:41 The c-style cats have been replaced with static_ca
+ new (other_item) DerivedElementType;
danakj 2015/06/23 20:01:12 can you leave a comment explaining this is overwri
pdr. 2015/06/23 21:42:42 Done. The comment now reads: // Construct a new el
+ }
using ListContainerBase::size;
using ListContainerBase::empty;
« no previous file with comments | « no previous file | cc/base/list_container.cc » ('j') | cc/base/list_container_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698