Changeset 37056 in webkit


Ignore:
Timestamp:
Sep 29, 2008 1:20:37 AM (16 years ago)
Author:
mrowe@apple.com
Message:

Apply the ASCII fast path optimization from StringImpl::lower to StringImpl::upper.
In the few places that we call .upper() in WebCore the strings represent things like
tag and attribute names, which are nearly always going to be ASCII.

Reviewed by Sam Weinig.

  • platform/text/StringImpl.cpp:

(WebCore::StringImpl::lower): If we have to resize the buffer, be sure to pass the new length
in to Unicode::toLower the second time.
(WebCore::StringImpl::upper):

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r37055 r37056  
     12008-09-29  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Apply the ASCII fast path optimization from StringImpl::lower to StringImpl::upper.
     6        In the few places that we call .upper() in WebCore the strings represent things like
     7        tag and attribute names, which are nearly always going to be ASCII.
     8
     9        * platform/text/StringImpl.cpp:
     10        (WebCore::StringImpl::lower): If we have to resize the buffer, be sure to pass the new length
     11        in to Unicode::toLower the second time.
     12        (WebCore::StringImpl::upper):
     13
    1142008-09-28  Mark Rowe  <mrowe@apple.com>
    215
  • trunk/WebCore/platform/text/StringImpl.cpp

    r36073 r37056  
    362362        return adopt(data);
    363363    data.resize(realLength);
    364     Unicode::toLower(data.characters(), length, m_data, m_length, &error);
     364    Unicode::toLower(data.characters(), realLength, m_data, m_length, &error);
    365365    if (error)
    366366        return this;
     
    370370PassRefPtr<StringImpl> StringImpl::upper()
    371371{
     372    StringBuffer data(m_length);
     373    int32_t length = m_length;
     374
     375    // Do a faster loop for the case where all the characters are ASCII.
     376    UChar ored = 0;
     377    for (int i = 0; i < length; i++) {
     378        UChar c = m_data[i];
     379        ored |= c;
     380        data[i] = toASCIIUpper(c);
     381    }
     382    if (!(ored & ~0x7F))
     383        return adopt(data);
     384
     385    // Do a slower implementation for cases that include non-ASCII characters.
    372386    bool error;
    373     int32_t length = Unicode::toUpper(0, 0, m_data, m_length, &error);
    374     StringBuffer data(length);
    375     Unicode::toUpper(data.characters(), length, m_data, m_length, &error);
     387    int32_t realLength = Unicode::toUpper(data.characters(), length, m_data, m_length, &error);
     388    if (!error && realLength == length)
     389        return adopt(data);
     390    data.resize(realLength);
     391    Unicode::toUpper(data.characters(), realLength, m_data, m_length, &error);
    376392    if (error)
    377393        return this;
Note: See TracChangeset for help on using the changeset viewer.