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

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: 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..8f602548718493f4e5b9a6f64db96e6ea9fd21b7 100644
--- a/Source/core/editing/iterators/TextIterator.cpp
+++ b/Source/core/editing/iterators/TextIterator.cpp
@@ -1093,16 +1093,19 @@ static String createPlainText(const EphemeralRangeTemplate<Strategy>& range, Tex
return emptyString();
TextIteratorAlgorithm<Strategy> it(range.startPosition(), range.endPosition(), behavior);
- // 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);
+ if (!it.atEnd()) {
yosin_UTC9 2015/08/26 01:23:21 Can we use early return pattern? if (it.atEnd())
sof 2015/08/26 06:32:21 That looks better, switched to an early return.
+ // The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192
+ static const unsigned initialCapacity = 1 << 15;
- for (; !it.atEnd(); it.advance()) {
- it.text().appendTextToStringBuilder(builder);
- bufferLength += it.length();
+ builder.reserveCapacity(initialCapacity);
+
+ for (; !it.atEnd(); it.advance()) {
+ it.text().appendTextToStringBuilder(builder);
+ bufferLength += it.length();
yosin_UTC9 2015/08/26 01:23:21 Optional: Do we need to sum result length up? It s
sof 2015/08/26 06:32:21 Just testing for builder.isEmpty() here would suff
+ }
}
if (!bufferLength)
« 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