Commit ebb8cdea authored by bratell@opera.com's avatar bratell@opera.com

Shrink canonicalizedTitle a bit.

Noticed that it was (in content_shell x64 for Linux) 421 and 425 bytes
which seemed excessive. Just rewrote it a bit to do less work for the
same result.

gcc (not even going to guess why createQualifiedName changed):
---------------------------------------------------------------------------------------------------------------------
 -635 - Source: /home/bratell/src/chromium/src/third_party/WebKit/Source/core/dom/Document.cpp - (gained 8, lost 643)
---------------------------------------------------------------------------------------------------------------------
  Grown symbols:
         +8: WebCore::Document::didChangeVisibilityState() type=t, (was 299 bytes, now 307 bytes)
  Shrunk symbols:
        -64: WebCore::createQualifiedName(WTF::AtomicString const&, WTF::AtomicString const&, WebCore::ExceptionState&) type=t, (was 1112 bytes, now 1048 bytes)
       -579: WebCore::Document::updateTitle(WTF::String const&) type=t, (was 1541 bytes, now 962 bytes)

clang:
  Shrunk symbols:
       -241: WebCore::Document::updateTitle(WTF::String const&) type=t, (was 1124 bytes, now 883 bytes)

Review URL: https://codereview.chromium.org/390003003

git-svn-id: svn://svn.chromium.org/blink/trunk@181746 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent aec4d4c6
...@@ -1320,49 +1320,28 @@ PassRefPtrWillBeRawPtr<Range> Document::caretRangeFromPoint(int x, int y) ...@@ -1320,49 +1320,28 @@ PassRefPtrWillBeRawPtr<Range> Document::caretRangeFromPoint(int x, int y)
template <typename CharacterType> template <typename CharacterType>
static inline String canonicalizedTitle(Document* document, const String& title) static inline String canonicalizedTitle(Document* document, const String& title)
{ {
const CharacterType* characters = title.getCharacters<CharacterType>();
unsigned length = title.length(); unsigned length = title.length();
unsigned i;
StringBuffer<CharacterType> buffer(length);
unsigned builderIndex = 0; unsigned builderIndex = 0;
const CharacterType* characters = title.getCharacters<CharacterType>();
// Skip leading spaces and leading characters that would convert to spaces StringBuffer<CharacterType> buffer(length);
for (i = 0; i < length; ++i) {
CharacterType c = characters[i];
if (!(c <= 0x20 || c == 0x7F))
break;
}
if (i == length)
return String();
// Replace control characters with spaces, and backslashes with currency symbols, and collapse whitespace. // Replace control characters with spaces and collapse whitespace.
bool previousCharWasWS = false; bool pendingWhitespace = false;
for (; i < length; ++i) { for (unsigned i = 0; i < length; ++i) {
CharacterType c = characters[i]; UChar32 c = characters[i];
if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) { if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) {
if (previousCharWasWS) if (builderIndex != 0)
continue; pendingWhitespace = true;
buffer[builderIndex++] = ' ';
previousCharWasWS = true;
} else { } else {
if (pendingWhitespace) {
buffer[builderIndex++] = ' ';
pendingWhitespace = false;
}
buffer[builderIndex++] = c; buffer[builderIndex++] = c;
previousCharWasWS = false;
} }
} }
buffer.shrink(builderIndex);
// Strip trailing spaces
while (builderIndex > 0) {
--builderIndex;
if (buffer[builderIndex] != ' ')
break;
}
if (!builderIndex && buffer[builderIndex] == ' ')
return String();
buffer.shrink(builderIndex + 1);
return String::adopt(buffer); return String::adopt(buffer);
} }
......
...@@ -52,19 +52,6 @@ public: ...@@ -52,19 +52,6 @@ public:
} }
void shrink(unsigned newLength); void shrink(unsigned newLength);
void resize(unsigned newLength)
{
if (!m_data) {
CharType* characters;
m_data = StringImpl::createUninitialized(newLength, characters);
return;
}
if (newLength > m_data->length()) {
m_data = StringImpl::reallocate(m_data.release(), newLength);
return;
}
shrink(newLength);
}
unsigned length() const { return m_data ? m_data->length() : 0; } unsigned length() const { return m_data ? m_data->length() : 0; }
CharType* characters() { return length() ? const_cast<CharType*>(m_data->getCharacters<CharType>()) : 0; } CharType* characters() { return length() ? const_cast<CharType*>(m_data->getCharacters<CharType>()) : 0; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment