Commit c3013ed8 authored by sigbjornf@opera.com's avatar sigbjornf@opera.com

createPlainText(): avoid a 32k buffer allocation for empty ranges.

The pre-allocation of the StringBuilder is redundant if the range is
empty, hence avoid.

While here, simplify empty string builder testing also.

R=yosin
BUG=

Review URL: https://codereview.chromium.org/1317593003

git-svn-id: svn://svn.chromium.org/blink/trunk@201212 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4a2e50c1
...@@ -1093,19 +1093,20 @@ static String createPlainText(const EphemeralRangeTemplate<Strategy>& range, Tex ...@@ -1093,19 +1093,20 @@ static String createPlainText(const EphemeralRangeTemplate<Strategy>& range, Tex
return emptyString(); return emptyString();
TextIteratorAlgorithm<Strategy> it(range.startPosition(), range.endPosition(), behavior); TextIteratorAlgorithm<Strategy> it(range.startPosition(), range.endPosition(), behavior);
if (it.atEnd())
return emptyString();
// The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192 // The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192
static const unsigned initialCapacity = 1 << 15; static const unsigned initialCapacity = 1 << 15;
unsigned bufferLength = 0;
StringBuilder builder; StringBuilder builder;
builder.reserveCapacity(initialCapacity); builder.reserveCapacity(initialCapacity);
for (; !it.atEnd(); it.advance()) { for (; !it.atEnd(); it.advance())
it.text().appendTextToStringBuilder(builder); it.text().appendTextToStringBuilder(builder);
bufferLength += it.length();
}
if (!bufferLength) if (builder.isEmpty())
return emptyString(); return emptyString();
return builder.toString(); return builder.toString();
......
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