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

Unified Diff: Source/wtf/Vector.h

Issue 23451016: Reorder the destruction sequence of Vector() to do less work. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months 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 a49fb68864c175df5ee972dd0b8fdea8f42aedf8..e5a998d2224b7e4c5601508b032373cb678e19d2 100644
--- a/Source/wtf/Vector.h
+++ b/Source/wtf/Vector.h
@@ -279,19 +279,6 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
}
- void deallocateBuffer(T* bufferToDeallocate)
- {
- if (!bufferToDeallocate)
- return;
-
- if (m_buffer == bufferToDeallocate) {
- m_buffer = 0;
- m_capacity = 0;
- }
-
- fastFree(bufferToDeallocate);
- }
-
T* buffer() { return m_buffer; }
const T* buffer() const { return m_buffer; }
size_t capacity() const { return m_capacity; }
@@ -342,6 +329,21 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
~VectorBuffer()
{
deallocateBuffer(buffer());
+ m_buffer = 0;
+ }
+
+ void deallocateBuffer(T* bufferToDeallocate)
+ {
+ if (LIKELY(!bufferToDeallocate))
+ return;
+
+ fastFree(bufferToDeallocate);
+ }
+
+ void clearBufferPointer()
+ {
+ m_buffer = 0;
+ m_capacity = 0;
}
void swap(VectorBuffer<T, 0>& other)
@@ -355,7 +357,6 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
using Base::allocateBuffer;
using Base::shouldReallocateBuffer;
using Base::reallocateBuffer;
- using Base::deallocateBuffer;
using Base::buffer;
using Base::capacity;
@@ -407,7 +408,14 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
{
if (LIKELY(bufferToDeallocate == inlineBuffer()))
return;
- Base::deallocateBuffer(bufferToDeallocate);
+
+ fastFree(bufferToDeallocate);
+ }
+
+ void clearBufferPointer()
+ {
+ m_buffer = 0;
+ m_capacity = 0;
}
bool shouldReallocateBuffer(size_t newCapacity) const
@@ -497,7 +505,7 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
~Vector()
{
- if (m_size)
+ if (UNLIKELY(m_size))
shrink(0);
}
@@ -874,6 +882,8 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
Base::allocateBuffer(newCapacity);
if (begin() != oldBuffer)
TypeOperations::move(oldBuffer, oldEnd, begin());
+ } else {
+ Base::clearBufferPointer();
}
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