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

Unified Diff: Source/core/dom/Document.cpp

Issue 390003003: Shrink canonicalizedTitle a bit. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased to newer origin/master Created 6 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 | Source/wtf/text/StringBuffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 39bdbdc2d5f0a5290b2ddd970a7c00a912fe2d8f..d9a630de3c73ca361085f431aac6b5feb906a181 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -1318,49 +1318,28 @@ PassRefPtrWillBeRawPtr<Range> Document::caretRangeFromPoint(int x, int y)
template <typename CharacterType>
static inline String canonicalizedTitle(Document* document, const String& title)
{
- const CharacterType* characters = title.getCharacters<CharacterType>();
unsigned length = title.length();
- unsigned i;
-
- StringBuffer<CharacterType> buffer(length);
unsigned builderIndex = 0;
+ const CharacterType* characters = title.getCharacters<CharacterType>();
- // Skip leading spaces and leading characters that would convert to spaces
- for (i = 0; i < length; ++i) {
- CharacterType c = characters[i];
- if (!(c <= 0x20 || c == 0x7F))
- break;
- }
-
- if (i == length)
- return String();
+ StringBuffer<CharacterType> buffer(length);
- // Replace control characters with spaces, and backslashes with currency symbols, and collapse whitespace.
- bool previousCharWasWS = false;
- for (; i < length; ++i) {
- CharacterType c = characters[i];
+ // Replace control characters with spaces and collapse whitespace.
+ bool pendingWhitespace = false;
+ for (unsigned i = 0; i < length; ++i) {
+ UChar32 c = characters[i];
if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) {
- if (previousCharWasWS)
- continue;
- buffer[builderIndex++] = ' ';
- previousCharWasWS = true;
+ if (builderIndex != 0)
+ pendingWhitespace = true;
} else {
+ if (pendingWhitespace) {
+ buffer[builderIndex++] = ' ';
+ pendingWhitespace = false;
+ }
buffer[builderIndex++] = c;
- previousCharWasWS = false;
}
}
-
- // Strip trailing spaces
- while (builderIndex > 0) {
- --builderIndex;
- if (buffer[builderIndex] != ' ')
- break;
- }
-
- if (!builderIndex && buffer[builderIndex] == ' ')
- return String();
-
- buffer.shrink(builderIndex + 1);
+ buffer.shrink(builderIndex);
return String::adopt(buffer);
}
« no previous file with comments | « no previous file | Source/wtf/text/StringBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698