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

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
« Source/wtf/DefaultAllocator.h ('K') | « 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..584117266813fbcd8501c2bfa417e1deb6a695ff 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,21 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
reallyDeallocateBuffer(bufferToDeallocate);
}
+ bool expandBuffer(size_t newCapacity)
+ {
+ if (newCapacity <= inlineCapacity)
tkent 2014/11/14 03:54:25 Is this check necessary? The callsite already has
haraken 2014/11/14 04:32:45 Removed.
+ return true;
+ 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 +974,8 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
return;
T* oldBuffer = begin();
T* oldEnd = end();
+ if (Base::expandBuffer(newCapacity))
tkent 2014/11/14 03:54:25 I'm afraid this change causes performance regressi
haraken 2014/11/14 04:32:45 I observe no regression in parser benchmarks that
+ return;
Base::allocateBuffer(newCapacity);
TypeOperations::move(oldBuffer, oldEnd, begin());
Base::deallocateBuffer(oldBuffer);
« Source/wtf/DefaultAllocator.h ('K') | « Source/wtf/Deque.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698