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

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

Issue 1193433004: Blink-side contiguous allocation of display items. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add ListContainer::AllocateAndConstructWithArguments and a TODO in DisplayItemList::findMatchingIte… 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 | « Source/platform/blink_platform.gypi ('k') | Source/platform/graphics/ListContainerTest.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 6d5f22ddc4772866346cdad32741666e34cbecd2..9da1ebf225c07b687da75d7e27789f607e3155a3 100644
--- a/Source/platform/graphics/ListContainer.h
+++ b/Source/platform/graphics/ListContainer.h
@@ -9,6 +9,7 @@
#include "wtf/Forward.h"
#include "wtf/Noncopyable.h"
#include "wtf/OwnPtr.h"
+#include "wtf/Utility.h"
#include "wtf/Vector.h"
#include <iterator>
@@ -234,18 +235,29 @@ public:
BaseElementType* elementAt(size_t index)
{
- return *Iterator(iteratorAt(index));
+ return *iteratorAt(index);
}
+
const BaseElementType* elementAt(size_t index) const
{
- return *ConstIterator(iteratorAt(index));
+ return *iteratorAt(index);
+ }
+
+ Iterator iteratorAt(size_t index)
+ {
+ return Iterator(ListContainerBase::iteratorAt(index));
+ }
+
+ ConstIterator iteratorAt(size_t index) const
+ {
+ return ConstIterator(ListContainerBase::iteratorAt(index));
}
// Take in derived element type and construct it at location generated by Allocate().
- template <typename DerivedElementType>
- DerivedElementType* allocateAndConstruct()
+ template <typename DerivedElementType, typename... Args>
+ DerivedElementType* allocateAndConstruct(Args&&... args)
{
- return new (allocate(sizeof(DerivedElementType))) DerivedElementType;
+ return new (allocate(sizeof(DerivedElementType))) DerivedElementType(WTF::forward<Args>(args)...);
}
// Take in derived element type and copy construct it at location generated by
@@ -273,15 +285,17 @@ public:
// 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()).
+ // of memory will be moved (up to maxSizeForDerivedClass()). A pointer
+ // to the moved element is returned.
template <typename DerivedElementType>
- void appendByMoving(DerivedElementType* item)
+ DerivedElementType* 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;
+ return static_cast<DerivedElementType*>(newItem);
}
using ListContainerBase::size;
@@ -326,6 +340,7 @@ public:
friend Iterator ListContainer<BaseElementType>::begin();
friend Iterator ListContainer<BaseElementType>::end();
friend BaseElementType* ListContainer<BaseElementType>::elementAt(size_t index);
+ friend Iterator ListContainer<BaseElementType>::iteratorAt(size_t index);
};
class ConstIterator : public ListContainerBase::ConstIterator {
@@ -364,6 +379,7 @@ public:
friend ConstIterator ListContainer<BaseElementType>::cbegin() const;
friend ConstIterator ListContainer<BaseElementType>::cend() const;
friend const BaseElementType* ListContainer<BaseElementType>::elementAt(size_t index) const;
+ friend ConstIterator ListContainer<BaseElementType>::iteratorAt(size_t index) const;
};
class ReverseIterator : public ListContainerBase::ReverseIterator {
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | Source/platform/graphics/ListContainerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698