text-transform: capitalize shouldn't upconvert
In looking at STRING_STATS for Mobile New York Times, I noticed that
text-transform: capitalize is bloating memory by upconverting strings. It's a
small amount of memory, but there's no reason to upconvert the strings.
After this CL, all the strings used by Mobile New York Times are fully
optimized (or at least they will be after
https://codereview.chromium.org/16158008/ lands).
R=eseidel
Review URL: https://chromiumcodereview.appspot.com/16501003
git-svn-id: svn://svn.chromium.org/blink/trunk@151976 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/Source/core/rendering/RenderText.cpp b/Source/core/rendering/RenderText.cpp
index ccd7165..dab9359 100644
--- a/Source/core/rendering/RenderText.cpp
+++ b/Source/core/rendering/RenderText.cpp
@@ -98,7 +98,7 @@
return;
unsigned length = string->length();
- const UChar* characters = string->characters();
+ const StringImpl& input = *string->impl();
if (length >= numeric_limits<unsigned>::max())
CRASH();
@@ -107,28 +107,29 @@
stringWithPrevious[0] = previous == noBreakSpace ? ' ' : previous;
for (unsigned i = 1; i < length + 1; i++) {
// Replace   with a real space since ICU no longer treats   as a word separator.
- if (characters[i - 1] == noBreakSpace)
+ if (input[i - 1] == noBreakSpace)
stringWithPrevious[i] = ' ';
else
- stringWithPrevious[i] = characters[i - 1];
+ stringWithPrevious[i] = input[i - 1];
}
TextBreakIterator* boundary = wordBreakIterator(stringWithPrevious.characters(), length + 1);
if (!boundary)
return;
- StringBuffer<UChar> data(length);
+ StringBuilder result;
+ result.reserveCapacity(length);
int32_t endOfWord;
int32_t startOfWord = textBreakFirst(boundary);
for (endOfWord = textBreakNext(boundary); endOfWord != TextBreakDone; startOfWord = endOfWord, endOfWord = textBreakNext(boundary)) {
if (startOfWord) // Ignore first char of previous string
- data[startOfWord - 1] = characters[startOfWord - 1] == noBreakSpace ? noBreakSpace : toTitleCase(stringWithPrevious[startOfWord]);
+ result.append(input[startOfWord - 1] == noBreakSpace ? noBreakSpace : toTitleCase(stringWithPrevious[startOfWord]));
for (int i = startOfWord + 1; i < endOfWord; i++)
- data[i - 1] = characters[i - 1];
+ result.append(input[i - 1]);
}
- *string = String::adopt(data);
+ *string = result.toString();
}
RenderText::RenderText(Node* node, PassRefPtr<StringImpl> str)