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

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: Minor tweaks to make reviewing easier 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
Index: Source/platform/graphics/ListContainer.h
diff --git a/Source/platform/graphics/ListContainer.h b/Source/platform/graphics/ListContainer.h
index 6d5f22ddc4772866346cdad32741666e34cbecd2..42098073ba44cfaf891079bb431dd3a9cf43b6bc 100644
--- a/Source/platform/graphics/ListContainer.h
+++ b/Source/platform/graphics/ListContainer.h
@@ -234,11 +234,39 @@ public:
BaseElementType* elementAt(size_t index)
{
- return *Iterator(iteratorAt(index));
+ return *iteratorAt(index);
danakj 2015/06/29 17:43:51 Is this a change we could/should make in cc/ too?
pdr. 2015/06/29 22:20:03 Done in https://codereview.chromium.org/1219753003
}
+
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));
+ }
+
+ BaseElementType& operator[](size_t index)
danakj 2015/06/29 17:43:51 I recommend not adding these. It looks like it sho
pdr. 2015/06/29 22:20:03 I added these for similar reasons. These are heavi
danakj 2015/06/29 22:29:47 ah OK. iteratorat sounds OK to me. operator[] less
+ {
+ return *elementAt(index);
+ }
+
+ const BaseElementType& operator[](size_t index) const
+ {
+ return *elementAt(index);
+ }
+
+ // Allocate a new, uninitialized DerivedElementType. Use with caution!
danakj 2015/06/29 17:43:51 Why do we need this?
pdr. 2015/06/29 22:20:03 We no longer do because I've made allocateAndConst
+ template <typename DerivedElementType>
+ DerivedElementType* allocateWithoutConstruction()
+ {
+ return static_cast<DerivedElementType*>(allocate(sizeof(DerivedElementType)));
}
// Take in derived element type and construct it at location generated by Allocate().
@@ -273,15 +301,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)
danakj 2015/06/29 17:43:51 Can we do this to the cc/ class too?
pdr. 2015/06/29 22:20:03 Done in https://codereview.chromium.org/1219753003
{
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 +356,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 +395,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 {

Powered by Google App Engine
This is Rietveld 408576698