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

Unified Diff: Source/wtf/text/StringBuilder.cpp

Issue 1220253004: Implement a fast buffer allocator for Vector, HashTable and StringBuilder Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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/testing/RunAllTests.cpp ('k') | Source/wtf/text/StringImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/text/StringBuilder.cpp
diff --git a/Source/wtf/text/StringBuilder.cpp b/Source/wtf/text/StringBuilder.cpp
index 9236bf6fb55526c337cbc82ed4074f5da8cbc934..29428f235d9075363b4070e525fa8886f343bdfe 100644
--- a/Source/wtf/text/StringBuilder.cpp
+++ b/Source/wtf/text/StringBuilder.cpp
@@ -36,7 +36,7 @@ namespace WTF {
static unsigned expandedCapacity(unsigned capacity, unsigned requiredLength)
{
static const unsigned minimumCapacity = 16;
- return std::max(requiredLength, std::max(minimumCapacity, capacity * 2));
+ return std::max(requiredLength, std::max(minimumCapacity, capacity * 5 / 4));
}
void StringBuilder::reifyString()
@@ -118,7 +118,7 @@ void StringBuilder::allocateBuffer(const LChar* currentCharacters, unsigned requ
{
ASSERT(m_is8Bit);
// Copy the existing data into a new buffer, set result to point to the end of the existing data.
- RefPtr<StringImpl> buffer = StringImpl::createUninitialized(requiredLength, m_bufferCharacters8);
+ RefPtr<StringImpl> buffer = StringImpl::createBufferUninitialized(requiredLength, m_bufferCharacters8, this);
memcpy(m_bufferCharacters8, currentCharacters, static_cast<size_t>(m_length) * sizeof(LChar)); // This can't overflow.
// Update the builder state.
@@ -132,7 +132,7 @@ void StringBuilder::allocateBuffer(const UChar* currentCharacters, unsigned requ
{
ASSERT(!m_is8Bit);
// Copy the existing data into a new buffer, set result to point to the end of the existing data.
- RefPtr<StringImpl> buffer = StringImpl::createUninitialized(requiredLength, m_bufferCharacters16);
+ RefPtr<StringImpl> buffer = StringImpl::createBufferUninitialized(requiredLength, m_bufferCharacters16, this);
memcpy(m_bufferCharacters16, currentCharacters, static_cast<size_t>(m_length) * sizeof(UChar)); // This can't overflow.
// Update the builder state.
@@ -146,7 +146,7 @@ void StringBuilder::allocateBufferUpConvert(const LChar* currentCharacters, unsi
{
ASSERT(m_is8Bit);
// Copy the existing data into a new buffer, set result to point to the end of the existing data.
- RefPtr<StringImpl> buffer = StringImpl::createUninitialized(requiredLength, m_bufferCharacters16);
+ RefPtr<StringImpl> buffer = StringImpl::createBufferUninitialized(requiredLength, m_bufferCharacters16, this);
for (unsigned i = 0; i < m_length; ++i)
m_bufferCharacters16[i] = currentCharacters[i];
@@ -168,10 +168,14 @@ void StringBuilder::reallocateBuffer<LChar>(unsigned requiredLength)
ASSERT(m_buffer->is8Bit());
if (m_buffer->hasOneRef()) {
- m_buffer = StringImpl::reallocate(m_buffer.release(), requiredLength);
+ m_buffer = StringImpl::reallocate(m_buffer.release(), requiredLength, this);
m_bufferCharacters8 = const_cast<LChar*>(m_buffer->characters8());
- } else
+ } else {
+#if BUFFER_ALLOCATOR_DEBUG
+ fprintf(stderr, "!m_buffer->hasOneRef()\n");
+#endif
allocateBuffer(m_buffer->characters8(), requiredLength);
+ }
}
template <>
@@ -184,10 +188,14 @@ void StringBuilder::reallocateBuffer<UChar>(unsigned requiredLength)
if (m_buffer->is8Bit()) {
allocateBufferUpConvert(m_buffer->characters8(), requiredLength);
} else if (m_buffer->hasOneRef()) {
- m_buffer = StringImpl::reallocate(m_buffer.release(), requiredLength);
+ m_buffer = StringImpl::reallocate(m_buffer.release(), requiredLength, this);
m_bufferCharacters16 = const_cast<UChar*>(m_buffer->characters16());
- } else
+ } else {
+#if BUFFER_ALLOCATOR_DEBUG
+ fprintf(stderr, "!m_buffer->hasOneRef()\n");
+#endif
allocateBuffer(m_buffer->characters16(), requiredLength);
+ }
}
void StringBuilder::reserveCapacity(unsigned newCapacity)
« no previous file with comments | « Source/wtf/testing/RunAllTests.cpp ('k') | Source/wtf/text/StringImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698