⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 102059 in webkit


Ignore:
Timestamp:
Dec 5, 2011, 3:56:49 PM (15 years ago)
Author:
benjamin@webkit.org
Message:

Update String::containsOnlyASCII() to handle 8 bits strings
https://bugs.webkit.org/show_bug.cgi?id=73799

Reviewed by Darin Adler.

Source/JavaScriptCore:

Implement String::containsOnlyASCII() so that it does not
call String::characters().

  • wtf/text/WTFString.h:

(WTF::String::containsOnlyASCII):

Source/WebCore:

When possible, change the call sites from charactersAreAllASCII()
to the optimized version String::containsOnlyASCII().

  • platform/KURL.cpp:

(WebCore::KURL::init):

  • platform/cf/BinaryPropertyList.cpp:

(WebCore::BinaryPropertyListPlan::writeStringObject):

  • platform/graphics/chromium/FontCacheChromiumWin.cpp:

(WebCore::FontCodepage::if):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r102057 r102059  
     12011-12-05  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Update String::containsOnlyASCII() to handle 8 bits strings
     4        https://bugs.webkit.org/show_bug.cgi?id=73799
     5
     6        Reviewed by Darin Adler.
     7
     8        Implement String::containsOnlyASCII() so that it does not
     9        call String::characters().
     10
     11        * wtf/text/WTFString.h:
     12        (WTF::String::containsOnlyASCII):
     13
    1142011-12-05  Filip Pizlo  <fpizlo@apple.com>
    215
  • trunk/Source/JavaScriptCore/wtf/text/WTFString.h

    r102028 r102059  
    6262// Declarations of string operations
    6363
    64 bool charactersAreAllASCII(const UChar*, size_t);
     64template<typename CharType> inline bool charactersAreAllASCII(const CharType* characters, size_t length);
    6565WTF_EXPORT_PRIVATE int charactersToIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
    6666WTF_EXPORT_PRIVATE int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
     
    374374    }
    375375
    376     bool containsOnlyASCII() const { return charactersAreAllASCII(characters(), length()); }
     376    bool containsOnlyASCII() const;
    377377    bool containsOnlyLatin1() const;
    378378    bool containsOnlyWhitespace() const { return !m_impl || m_impl->containsOnlyWhitespace(); }
     
    483483#endif
    484484
    485 inline bool charactersAreAllASCII(const UChar* characters, size_t length)
    486 {
    487     UChar ored = 0;
     485template<typename CharType>
     486inline bool charactersAreAllASCII(const CharType* characters, size_t length)
     487{
     488    CharType ored = 0;
    488489    for (size_t i = 0; i < length; ++i)
    489490        ored |= characters[i];
    490     return !(ored & 0xFF80);
     491
     492    CharType lowBits = 0x7F;
     493    return !(ored & ~lowBits);
     494}
     495
     496inline bool String::containsOnlyASCII() const
     497{
     498    if (isEmpty())
     499        return true;
     500
     501    if (is8Bit())
     502        return charactersAreAllASCII(characters8(), m_impl->length());
     503
     504    return charactersAreAllASCII(characters16(), m_impl->length());
    491505}
    492506
  • trunk/Source/WebCore/ChangeLog

    r102055 r102059  
     12011-12-05  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Update String::containsOnlyASCII() to handle 8 bits strings
     4        https://bugs.webkit.org/show_bug.cgi?id=73799
     5
     6        Reviewed by Darin Adler.
     7
     8        When possible, change the call sites from charactersAreAllASCII()
     9        to the optimized version String::containsOnlyASCII().
     10
     11        * platform/KURL.cpp:
     12        (WebCore::KURL::init):
     13        * platform/cf/BinaryPropertyList.cpp:
     14        (WebCore::BinaryPropertyListPlan::writeStringObject):
     15        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
     16        (WebCore::FontCodepage::if):
     17
    1182011-12-01  Vangelis Kokkevis  <vangelis@chromium.org>
    219
  • trunk/Source/WebCore/platform/KURL.cpp

    r101713 r102059  
    377377        rel = substituteBackslashes(rel);
    378378
    379     bool allASCII = charactersAreAllASCII(rel.characters(), rel.length());
     379    bool allASCII = rel.containsOnlyASCII();
    380380    CharBuffer strBuffer;
    381381    char* str;
  • trunk/Source/WebCore/platform/cf/BinaryPropertyList.cpp

    r81548 r102059  
    286286void BinaryPropertyListPlan::writeStringObject(const String& string)
    287287{
    288     const UChar* characters = string.characters();
    289288    unsigned length = string.length();
    290289    m_byteCount += markerPlusLengthByteCount(length) + length;
    291     if (!charactersAreAllASCII(characters, length))
     290    if (!string.containsOnlyASCII())
    292291        m_byteCount += length;
    293292}
  • trunk/Source/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp

    r95901 r102059  
    5050namespace WebCore
    5151{
    52 
    53 // FIXME: consider adding to WebKit String class
    54 static bool charactersAreAllASCII(const String& s)
    55 {
    56     return WTF::charactersAreAllASCII(s.characters(), s.length());
    57 }
    5852
    5953// When asked for a CJK font with a native name under a non-CJK locale or
     
    217211    // For non-ASCII names, we don't want to invoke an expensive
    218212    // and unnecessary |lower|.
    219     if (charactersAreAllASCII(name)) {
     213    if (name.containsOnlyASCII()) {
    220214        isAscii = true;
    221215        n = name.lower();
Note: See TracChangeset for help on using the changeset viewer.