| Index: Source/wtf/Vector.h
|
| diff --git a/Source/wtf/Vector.h b/Source/wtf/Vector.h
|
| index 73109886a62342173678942825b2738a35242467..719f0309c3b74f5896ce7c24b7c550f54b51fd2a 100644
|
| --- a/Source/wtf/Vector.h
|
| +++ b/Source/wtf/Vector.h
|
| @@ -276,27 +276,27 @@ static const size_t kInitialVectorSize = 16;
|
| m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
|
| }
|
|
|
| - T* buffer() { return m_buffer; }
|
| - const T* buffer() const { return m_buffer; }
|
| - size_t capacity() const { return m_capacity; }
|
| + ALWAYS_INLINE T* buffer() { return m_buffer; }
|
| + ALWAYS_INLINE const T* buffer() const { return m_buffer; }
|
| + ALWAYS_INLINE size_t capacity() const { return m_capacity; }
|
|
|
| protected:
|
| VectorBufferBase()
|
| : m_buffer(0)
|
| , m_capacity(0)
|
| + , m_size(0)
|
| {
|
| }
|
|
|
| VectorBufferBase(T* buffer, size_t capacity)
|
| : m_buffer(buffer)
|
| , m_capacity(capacity)
|
| + , m_size(0)
|
| {
|
| }
|
|
|
| ~VectorBufferBase()
|
| {
|
| - m_buffer = 0;
|
| - m_size = 0;
|
| }
|
|
|
| T* m_buffer;
|
| @@ -324,6 +324,10 @@ static const size_t kInitialVectorSize = 16;
|
| allocateBuffer(capacity);
|
| }
|
|
|
| + ~VectorBuffer()
|
| + {
|
| + }
|
| +
|
| void deallocateBuffer(T* bufferToDeallocate)
|
| {
|
| fastFree(bufferToDeallocate);
|
| @@ -335,9 +339,10 @@ static const size_t kInitialVectorSize = 16;
|
| m_capacity = 0;
|
| }
|
|
|
| - ~VectorBuffer()
|
| + void destruct()
|
| {
|
| - deallocateBuffer(buffer());
|
| + deallocateBuffer(m_buffer);
|
| + m_buffer = 0;
|
| }
|
|
|
| void swap(VectorBuffer<T, 0>& other)
|
| @@ -381,21 +386,26 @@ static const size_t kInitialVectorSize = 16;
|
| Base::allocateBuffer(capacity);
|
| }
|
|
|
| + ~VectorBuffer()
|
| + {
|
| + }
|
| +
|
| void deallocateBuffer(T* bufferToDeallocate)
|
| {
|
| if (UNLIKELY(bufferToDeallocate != inlineBuffer()))
|
| fastFree(bufferToDeallocate);
|
| }
|
|
|
| - void clearBufferPointer()
|
| + void destruct()
|
| {
|
| + deallocateBuffer(m_buffer);
|
| m_buffer = 0;
|
| - m_capacity = 0;
|
| }
|
|
|
| - ~VectorBuffer()
|
| + void clearBufferPointer()
|
| {
|
| - deallocateBuffer(buffer());
|
| + m_buffer = 0;
|
| + m_capacity = 0;
|
| }
|
|
|
| void allocateBuffer(size_t newCapacity)
|
| @@ -461,8 +471,8 @@ static const size_t kInitialVectorSize = 16;
|
| using Base::m_capacity;
|
|
|
| static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T);
|
| - T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer); }
|
| - const T* inlineBuffer() const { return reinterpret_cast_ptr<const T*>(m_inlineBuffer.buffer); }
|
| + ALWAYS_INLINE T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer); }
|
| + ALWAYS_INLINE const T* inlineBuffer() const { return reinterpret_cast_ptr<const T*>(m_inlineBuffer.buffer); }
|
|
|
| AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer;
|
| };
|
| @@ -484,7 +494,7 @@ static const size_t kInitialVectorSize = 16;
|
|
|
| Vector()
|
| {
|
| - m_size = 0;
|
| + // Initialization occurs on the base classes.
|
| }
|
|
|
| explicit Vector(size_t size)
|
| @@ -496,7 +506,15 @@ static const size_t kInitialVectorSize = 16;
|
|
|
| ~Vector()
|
| {
|
| - shrink(0);
|
| + if (!inlineCapacity) {
|
| + if (LIKELY(!Base::buffer()))
|
| + return;
|
| + shrink(0);
|
| + } else {
|
| + if (UNLIKELY(m_size))
|
| + shrink(0);
|
| + }
|
| + Base::destruct();
|
| }
|
|
|
| Vector(const Vector&);
|
| @@ -512,9 +530,9 @@ static const size_t kInitialVectorSize = 16;
|
| Vector& operator=(Vector&&);
|
| #endif
|
|
|
| - size_t size() const { return m_size; }
|
| - size_t capacity() const { return Base::capacity(); }
|
| - bool isEmpty() const { return !size(); }
|
| + ALWAYS_INLINE size_t size() const { return m_size; }
|
| + ALWAYS_INLINE size_t capacity() const { return Base::capacity(); }
|
| + ALWAYS_INLINE bool isEmpty() const { return !size(); }
|
|
|
| T& at(size_t i)
|
| {
|
|
|