| Index: third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
|
| diff --git a/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h b/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
|
| index a50431becefb31c3ab4a231c74212f66ea67bf33..fab626541f9f828934650f9993d35ca6b41ee64e 100644
|
| --- a/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
|
| +++ b/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
|
| @@ -55,7 +55,7 @@ protected:
|
|
|
| // These do not invoke constructors or destructors.
|
| void reserveInitialCapacity(size_t, const char* typeName);
|
| - void* allocate(size_t objectSize, const char* typeName);
|
| + void* allocate(size_t objectSize, size_t alignment, const char* typeName);
|
| void removeLast();
|
| void clear();
|
| void swap(ContiguousContainerBase&);
|
| @@ -72,13 +72,7 @@ private:
|
| size_t m_maxObjectSize;
|
| };
|
|
|
| -// For most cases, no alignment stricter than pointer alignment is required. If
|
| -// one of the derived classes has stronger alignment requirements (and the
|
| -// static_assert fires), set alignment to the LCM of the derived class
|
| -// alignments. For small structs without pointers, it may be possible to reduce
|
| -// alignment for tighter packing.
|
| -
|
| -template <class BaseElementType, unsigned alignment = sizeof(void*)>
|
| +template <class BaseElementType>
|
| class ContiguousContainer : public ContiguousContainerBase {
|
| private:
|
| // Declares itself as a forward iterator, but also supports a few more
|
| @@ -108,7 +102,7 @@ public:
|
| using reverse_iterator = IteratorWrapper<Vector<void*>::reverse_iterator, BaseElementType>;
|
| using const_reverse_iterator = IteratorWrapper<Vector<void*>::const_reverse_iterator, const BaseElementType>;
|
|
|
| - explicit ContiguousContainer(size_t maxObjectSize) : ContiguousContainerBase(align(maxObjectSize)) {}
|
| + explicit ContiguousContainer(size_t maxObjectSize) : ContiguousContainerBase(maxObjectSize) {}
|
|
|
| ContiguousContainer(size_t maxObjectSize, size_t initialSizeBytes)
|
| : ContiguousContainer(maxObjectSize)
|
| @@ -164,10 +158,8 @@ public:
|
| {
|
| static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::value,
|
| "Must use subclass of BaseElementType.");
|
| - static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0,
|
| - "Derived type requires stronger alignment.");
|
| - size_t allocSize = align(sizeof(DerivedElementType));
|
| - return *new (allocate(allocSize)) DerivedElementType(std::forward<Args>(args)...);
|
| + return *new (allocate(sizeof(DerivedElementType), WTF_ALIGN_OF(DerivedElementType)))
|
| + DerivedElementType(std::forward<Args>(args)...);
|
| }
|
|
|
| void removeLast()
|
| @@ -190,28 +182,21 @@ public:
|
|
|
| // Appends a new element using memcpy, then default-constructs a base
|
| // element in its place. Use with care.
|
| - BaseElementType& appendByMoving(BaseElementType& item, size_t size)
|
| + BaseElementType& appendByMoving(BaseElementType& item, size_t size, size_t alignment)
|
| {
|
| ASSERT(size >= sizeof(BaseElementType));
|
| - void* newItem = allocate(size);
|
| + void* newItem = allocate(size, alignment);
|
| memcpy(newItem, static_cast<void*>(&item), size);
|
| new (&item) BaseElementType;
|
| return *static_cast<BaseElementType*>(newItem);
|
| }
|
|
|
| private:
|
| - void* allocate(size_t objectSize)
|
| - {
|
| - return ContiguousContainerBase::allocate(objectSize, WTF_HEAP_PROFILER_TYPE_NAME(BaseElementType));
|
| - }
|
| + FRIEND_TEST_ALL_PREFIXES(ContiguousContainerTest, Alignment);
|
|
|
| - static size_t align(size_t size)
|
| + void* allocate(size_t objectSize, size_t alignment)
|
| {
|
| - size_t alignedSize = alignment * ((size + alignment - 1) / alignment);
|
| - ASSERT(alignedSize % alignment == 0);
|
| - ASSERT(alignedSize >= size);
|
| - ASSERT(alignedSize < size + alignment);
|
| - return alignedSize;
|
| + return ContiguousContainerBase::allocate(objectSize, alignment, WTF_HEAP_PROFILER_TYPE_NAME(BaseElementType));
|
| }
|
| };
|
|
|
|
|