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

Unified Diff: Source/core/editing/iterators/TextIterator.cpp

Issue 1317593003: createPlainText(): avoid a 32k buffer allocation for empty ranges. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: simplify empty builder testing 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/iterators/TextIterator.cpp
diff --git a/Source/core/editing/iterators/TextIterator.cpp b/Source/core/editing/iterators/TextIterator.cpp
index 0c9aa7edc6b851be5426c5e81f8d33c49afe9bb8..017f40923f6673800e119b81a2df474b6d0d0404 100644
--- a/Source/core/editing/iterators/TextIterator.cpp
+++ b/Source/core/editing/iterators/TextIterator.cpp
@@ -1093,19 +1093,20 @@ static String createPlainText(const EphemeralRangeTemplate<Strategy>& range, Tex
return emptyString();
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
static const unsigned initialCapacity = 1 << 15;
- unsigned bufferLength = 0;
StringBuilder builder;
builder.reserveCapacity(initialCapacity);
- for (; !it.atEnd(); it.advance()) {
+ for (; !it.atEnd(); it.advance())
it.text().appendTextToStringBuilder(builder);
- bufferLength += it.length();
- }
- if (!bufferLength)
+ if (builder.isEmpty())
return emptyString();
return builder.toString();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698