Commit 25fdbad2 authored by esprehn's avatar esprehn Committed by Commit bot

StringBuilder::append should not use reserveCapacity.

reserveCapacity allocates the exact capacity specified which means
when we had a 16bit buffer in StringBuilder and were appending 8bit
strings to it we were constantly reallocating and copying the buffer.

Instead we can just call Vector::append() directly since it has a
template overload that can accept implicitly convertible types.

I noticed this when looking at lever.co's web app loading in
Instruments, it was spending 15% of the main thread time inside
TextResource::decodedText which was 83% memmove, and 11% munmap.

Switching to Vector::append should restore the correct size
doubling behavior when appending LChars to a UChar StringBuilder
and make this much faster.

This was a regression from when I switched to using a Vector
inside StringBuilder in:
https://codereview.chromium.org/2046353002

Review-Url: https://codereview.chromium.org/2192293002
Cr-Commit-Position: refs/heads/master@{#408869}
parent 6dfb2b2c
...@@ -200,9 +200,7 @@ void StringBuilder::append(const LChar* characters, unsigned length) ...@@ -200,9 +200,7 @@ void StringBuilder::append(const LChar* characters, unsigned length)
ensureBuffer16(length); ensureBuffer16(length);
m_string = String(); m_string = String();
m_buffer16->reserveCapacity(m_buffer16->size() + length); m_buffer16->append(characters, length);
for (size_t i = 0; i < length; ++i)
m_buffer16->uncheckedAppend(characters[i]);
m_length += length; m_length += length;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment