Chromium Code Reviews| 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)...); |
|
danakj
2015/06/30 18:49:01
Can you add a unit test with non-0 number of argum
pdr.
2015/06/30 22:16:06
Done, added ListContainerTest::AllocateAndConstruc
|
| } |
| // 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 { |