Changeset 153007 in webkit


Ignore:
Timestamp:
Jul 22, 2013 3:29:03 PM (11 years ago)
Author:
benjamin@webkit.org
Message:

String::lower() - Skip to slow path on the first failure
https://bugs.webkit.org/show_bug.cgi?id=118885

Reviewed by Andreas Kling.

In the 8 bits case, we don't need to know the state of the full string before changing characters
to their lowercase variant.
Just fail immediately and start transforming characters from the point of failure.

This avoid reading the string twice when the uppercase character is not at the end of the string.

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::lower):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r152973 r153007  
     12013-07-22  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        String::lower() - Skip to slow path on the first failure
     4        https://bugs.webkit.org/show_bug.cgi?id=118885
     5
     6        Reviewed by Andreas Kling.
     7
     8        In the 8 bits case, we don't need to know the state of the full string before changing characters
     9        to their lowercase variant.
     10        Just fail immediately and start transforming characters from the point of failure.
     11
     12        This avoid reading the string twice when the uppercase character is not at the end of the string.
     13
     14        * wtf/text/StringImpl.cpp:
     15        (WTF::StringImpl::lower):
     16
    1172013-07-22  Brent Fulgham  <bfulgham@apple.com>
    218
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r152883 r153007  
    393393    // First scan the string for uppercase and non-ASCII characters:
    394394    bool noUpper = true;
    395     unsigned ored = 0;
    396395    if (is8Bit()) {
     396        unsigned failingIndex;
    397397        for (unsigned i = 0; i < m_length; ++i) {
    398398            LChar character = m_data8[i];
    399             if (UNLIKELY(isASCIIUpper(character)))
    400                 noUpper = false;
    401             ored |= character;
    402         }
    403         // Nothing to do if the string is all ASCII with no uppercase.
    404         if (noUpper && !(ored & ~0x7F))
    405             return this;
    406 
     399            if (UNLIKELY((character & ~0x7F) || isASCIIUpper(character))) {
     400                failingIndex = i;
     401                goto SlowPath8bitLower;
     402            }
     403        }
     404        return this;
     405
     406SlowPath8bitLower:
    407407        LChar* data8;
    408408        RefPtr<StringImpl> newImpl = createUninitialized(m_length, data8);
    409409
    410         if (!(ored & ~0x7F)) {
    411             for (unsigned i = 0; i < m_length; ++i)
    412                 data8[i] = toASCIILower(m_data8[i]);
    413 
    414             return newImpl.release();
    415         }
    416 
    417         // Do a slower implementation for cases that include non-ASCII Latin-1 characters.
    418         for (unsigned i = 0; i < m_length; ++i)
    419             data8[i] = static_cast<LChar>(Unicode::toLower(m_data8[i]));
     410        for (unsigned i = 0; i < failingIndex; ++i)
     411            data8[i] = m_data8[i];
     412
     413        for (unsigned i = failingIndex; i < m_length; ++i) {
     414            LChar character = m_data8[i];
     415            if (!(character & ~0x7F))
     416                data8[i] = toASCIILower(character);
     417            else
     418                data8[i] = static_cast<LChar>(Unicode::toLower(character));
     419        }
    420420
    421421        return newImpl.release();
    422422    }
     423    unsigned ored = 0;
    423424
    424425    for (unsigned i = 0; i < m_length; ++i) {
Note: See TracChangeset for help on using the changeset viewer.