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

Unified Diff: Source/wtf/Vector.h

Issue 720163002: Oilpan: Vector::reserveCapacity shouldn't reallocate backing storage always (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « Source/wtf/Deque.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « Source/wtf/Deque.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698