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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/text/StringBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 1311
1312 /* 1312 /*
1313 * Performs three operations: 1313 * Performs three operations:
1314 * 1. Convert control characters to spaces 1314 * 1. Convert control characters to spaces
1315 * 2. Trim leading and trailing spaces 1315 * 2. Trim leading and trailing spaces
1316 * 3. Collapse internal whitespace. 1316 * 3. Collapse internal whitespace.
1317 */ 1317 */
1318 template <typename CharacterType> 1318 template <typename CharacterType>
1319 static inline String canonicalizedTitle(Document* document, const String& title) 1319 static inline String canonicalizedTitle(Document* document, const String& title)
1320 { 1320 {
1321 unsigned length = title.length();
1322 unsigned builderIndex = 0;
1321 const CharacterType* characters = title.getCharacters<CharacterType>(); 1323 const CharacterType* characters = title.getCharacters<CharacterType>();
1322 unsigned length = title.length();
1323 unsigned i;
1324 1324
1325 StringBuffer<CharacterType> buffer(length); 1325 StringBuffer<CharacterType> buffer(length);
1326 unsigned builderIndex = 0;
1327 1326
1328 // Skip leading spaces and leading characters that would convert to spaces 1327 // Replace control characters with spaces and collapse whitespace.
1329 for (i = 0; i < length; ++i) { 1328 bool pendingWhitespace = false;
1330 CharacterType c = characters[i]; 1329 for (unsigned i = 0; i < length; ++i) {
1331 if (!(c <= 0x20 || c == 0x7F)) 1330 UChar32 c = characters[i];
1332 break;
1333 }
1334
1335 if (i == length)
1336 return String();
1337
1338 // Replace control characters with spaces, and backslashes with currency sym bols, and collapse whitespace.
1339 bool previousCharWasWS = false;
1340 for (; i < length; ++i) {
1341 CharacterType c = characters[i];
1342 if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode ::Separator_Line | WTF::Unicode::Separator_Paragraph))) { 1331 if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode ::Separator_Line | WTF::Unicode::Separator_Paragraph))) {
1343 if (previousCharWasWS) 1332 if (builderIndex != 0)
1344 continue; 1333 pendingWhitespace = true;
1345 buffer[builderIndex++] = ' ';
1346 previousCharWasWS = true;
1347 } else { 1334 } else {
1335 if (pendingWhitespace) {
1336 buffer[builderIndex++] = ' ';
1337 pendingWhitespace = false;
1338 }
1348 buffer[builderIndex++] = c; 1339 buffer[builderIndex++] = c;
1349 previousCharWasWS = false;
1350 } 1340 }
1351 } 1341 }
1352 1342 buffer.shrink(builderIndex);
1353 // Strip trailing spaces
1354 while (builderIndex > 0) {
1355 --builderIndex;
1356 if (buffer[builderIndex] != ' ')
1357 break;
1358 }
1359
1360 if (!builderIndex && buffer[builderIndex] == ' ')
1361 return String();
1362
1363 buffer.shrink(builderIndex + 1);
1364 1343
1365 return String::adopt(buffer); 1344 return String::adopt(buffer);
1366 } 1345 }
1367 1346
1368 void Document::updateTitle(const String& title) 1347 void Document::updateTitle(const String& title)
1369 { 1348 {
1370 if (m_rawTitle == title) 1349 if (m_rawTitle == title)
1371 return; 1350 return;
1372 1351
1373 m_rawTitle = title; 1352 m_rawTitle = title;
(...skipping 4446 matching lines...) Expand 10 before | Expand all | Expand 10 after
5820 using namespace blink; 5799 using namespace blink;
5821 void showLiveDocumentInstances() 5800 void showLiveDocumentInstances()
5822 { 5801 {
5823 WeakDocumentSet& set = liveDocumentSet(); 5802 WeakDocumentSet& set = liveDocumentSet();
5824 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5803 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5825 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { 5804 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) {
5826 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); 5805 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data());
5827 } 5806 }
5828 } 5807 }
5829 #endif 5808 #endif
OLDNEW
« 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