Index: Source/wtf/Vector.h |
diff --git a/Source/wtf/Vector.h b/Source/wtf/Vector.h |
index 0912c2cebc7469b36e1d680028fdbf8b36d0dac0..44e975633d31a3bd241bff863759adf0af1663de 100644 |
--- a/Source/wtf/Vector.h |
+++ b/Source/wtf/Vector.h |
@@ -359,6 +359,16 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
Allocator::backingFree(bufferToDeallocate); |
} |
+ bool expandBuffer(size_t newCapacity) |
+ { |
+ size_t sizeToAllocate = allocationSize(newCapacity); |
+ if (Allocator::backingExpand(m_buffer, sizeToAllocate)) { |
+ m_capacity = sizeToAllocate / sizeof(T); |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
void resetBufferPointer() |
{ |
m_buffer = 0; |
@@ -428,6 +438,20 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
reallyDeallocateBuffer(bufferToDeallocate); |
} |
+ bool expandBuffer(size_t newCapacity) |
+ { |
+ ASSERT(newCapacity > inlineCapacity); |
+ if (m_buffer == inlineBuffer()) |
+ return false; |
+ |
+ size_t sizeToAllocate = allocationSize(newCapacity); |
+ if (Allocator::backingExpand(m_buffer, sizeToAllocate)) { |
+ m_capacity = sizeToAllocate / sizeof(T); |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
void resetBufferPointer() |
{ |
m_buffer = inlineBuffer(); |
@@ -949,6 +973,8 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; |
return; |
T* oldBuffer = begin(); |
T* oldEnd = end(); |
+ if (Base::expandBuffer(newCapacity)) |
+ return; |
Base::allocateBuffer(newCapacity); |
TypeOperations::move(oldBuffer, oldEnd, begin()); |
Base::deallocateBuffer(oldBuffer); |