| 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)
|
|
|