Changeset 94475 in webkit for trunk/Source/JavaScriptCore


Ignore:
Timestamp:
Sep 2, 2011, 6:08:10 PM (14 years ago)
Author:
[email protected]
Message:

Replace local implementation of string equals() methods with UString versions
https://bugs.webkit.org/show_bug.cgi?id=67342

In preparation to allowing StringImpl to be backed by 8 bit
characters when appropriate, we need to eliminate or change the
usage of StringImpl::characters(). Change the uses of characters()
that are used to implement redundant equals() methods.

Reviewed by Gavin Barraclough.

  • runtime/Identifier.cpp:

(JSC::Identifier::equal):

  • runtime/Identifier.h:

(JSC::Identifier::equal):

  • wtf/text/AtomicString.cpp:

(WTF::CStringTranslator::equal): Moved an optimized method to here.
(WTF::operator==):

  • wtf/text/StringImpl.cpp:

(WTF::equal):

  • wtf/text/StringImpl.h:
Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r94470 r94475  
     12011-09-02  Michael Saboff  <[email protected]>
     2
     3        Replace local implementation of string equals() methods with UString versions
     4        https://bugs.webkit.org/show_bug.cgi?id=67342
     5
     6        In preparation to allowing StringImpl to be backed by 8 bit
     7        characters when appropriate, we need to eliminate or change the
     8        usage of StringImpl::characters(). Change the uses of characters()
     9        that are used to implement redundant equals() methods.
     10
     11        Reviewed by Gavin Barraclough.
     12
     13        * runtime/Identifier.cpp:
     14        (JSC::Identifier::equal):
     15        * runtime/Identifier.h:
     16        (JSC::Identifier::equal):
     17        * wtf/text/AtomicString.cpp:
     18        (WTF::CStringTranslator::equal): Moved an optimized method to here.
     19        (WTF::operator==):
     20        * wtf/text/StringImpl.cpp:
     21        (WTF::equal):
     22        * wtf/text/StringImpl.h:
     23
    1242011-09-02  Michael Saboff  <[email protected]>
    225
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r94470 r94475  
    109109__ZN3JSC10Identifier4fromEPNS_9ExecStateEi
    110110__ZN3JSC10Identifier4fromEPNS_9ExecStateEj
    111 __ZN3JSC10Identifier5equalEPKN3WTF10StringImplEPKc
    112111__ZN3JSC10Identifier8toUInt32ERKNS_7UStringERb
    113112__ZN3JSC10JSFunction14finishCreationEPNS_9ExecStateEPNS_14JSGlobalObjectEPNS_18FunctionExecutableEPNS_14ScopeChainNodeE
     
    478477__ZN3WTF5MutexD1Ev
    479478__ZN3WTF5equalEPKNS_10StringImplEPKc
     479__ZN3WTF5equalEPKNS_10StringImplEPKtj
    480480__ZN3WTF5equalEPKNS_10StringImplES2_
    481481__ZN3WTF5yieldEv
     
    525525__ZN3WTF9emptyAtomE
    526526__ZN3WTF9xmlnsAtomE
    527 __ZN3WTFeqERKNS_12AtomicStringEPKc
    528 __ZN3WTFeqERKNS_12AtomicStringERKNS_6VectorItLm0EEE
    529527__ZN3WTFeqERKNS_7CStringES2_
    530528__ZNK3JSC10JSFunction23isHostFunctionNonInlineEv
  • trunk/Source/JavaScriptCore/runtime/Identifier.cpp

    r94336 r94475  
    6868}
    6969
    70 bool Identifier::equal(const StringImpl* r, const char* s)
    71 {
    72     int length = r->length();
    73     const UChar* d = r->characters();
    74     for (int i = 0; i != length; ++i)
    75         if (d[i] != (unsigned char)s[i])
    76             return false;
    77     return s[length] == 0;
    78 }
    79 
    8070struct IdentifierCStringTranslator {
    8171    static unsigned hash(const char* c)
  • trunk/Source/JavaScriptCore/runtime/Identifier.h

    r88668 r94475  
    136136    }
    137137
     138    inline bool Identifier::equal(const StringImpl* r, const char* s)
     139    {
     140        return WTF::equal(r, s);
     141    }
     142   
    138143    inline bool Identifier::equal(const StringImpl* r, const UChar* s, unsigned length)
    139144    {
    140         if (r->length() != length)
    141             return false;
    142         const UChar* d = r->characters();
    143         for (unsigned i = 0; i != length; ++i)
    144             if (d[i] != s[i])
    145                 return false;
    146         return true;
     145        return WTF::equal(r, s, length);
    147146    }
    148147   
  • trunk/Source/JavaScriptCore/wtf/text/AtomicString.cpp

    r89906 r94475  
    9191    }
    9292
    93     static bool equal(StringImpl* r, const char* s)
    94     {
    95         int length = r->length();
    96         const UChar* d = r->characters();
    97         for (int i = 0; i != length; ++i) {
    98             unsigned char c = s[i];
    99             if (d[i] != c)
    100                 return false;
    101         }
    102         return !s[length];
     93    static inline bool equal(StringImpl* r, const char* s)
     94    {
     95        return WTF::equal(r, s);
    10396    }
    10497
     
    111104};
    112105
    113 bool operator==(const AtomicString& a, const char* b)
    114 {
    115     StringImpl* impl = a.impl();
    116     if ((!impl || !impl->characters()) && !b)
    117         return true;
    118     if ((!impl || !impl->characters()) || !b)
    119         return false;
    120     return CStringTranslator::equal(impl, b);
    121 }
    122 
    123106PassRefPtr<StringImpl> AtomicString::add(const char* c)
    124107{
     
    135118    unsigned length;
    136119};
    137 
    138 static inline bool equal(StringImpl* string, const UChar* characters, unsigned length)
    139 {
    140     if (string->length() != length)
    141         return false;
    142 
    143     // FIXME: perhaps we should have a more abstract macro that indicates when
    144     // going 4 bytes at a time is unsafe
    145 #if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC)
    146     const UChar* stringCharacters = string->characters();
    147     for (unsigned i = 0; i != length; ++i) {
    148         if (*stringCharacters++ != *characters++)
    149             return false;
    150     }
    151     return true;
    152 #else
    153     /* Do it 4-bytes-at-a-time on architectures where it's safe */
    154 
    155     const uint32_t* stringCharacters = reinterpret_cast<const uint32_t*>(string->characters());
    156     const uint32_t* bufferCharacters = reinterpret_cast<const uint32_t*>(characters);
    157 
    158     unsigned halfLength = length >> 1;
    159     for (unsigned i = 0; i != halfLength; ++i) {
    160         if (*stringCharacters++ != *bufferCharacters++)
    161             return false;
    162     }
    163 
    164     if (length & 1 &&  *reinterpret_cast<const uint16_t*>(stringCharacters) != *reinterpret_cast<const uint16_t*>(bufferCharacters))
    165         return false;
    166 
    167     return true;
    168 #endif
    169 }
    170 
    171 bool operator==(const AtomicString& string, const Vector<UChar>& vector)
    172 {
    173     return string.impl() && equal(string.impl(), vector.data(), vector.size());
    174 }
    175120
    176121struct UCharBufferTranslator {
  • trunk/Source/JavaScriptCore/wtf/text/AtomicString.h

    r89906 r94475  
    136136inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); }
    137137bool operator==(const AtomicString& a, const char* b);
    138 bool operator==(const AtomicString& a, const Vector<UChar>& b);
     138inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal(a.impl(), b); }
     139inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); }   
    139140inline bool operator==(const AtomicString& a, const String& b) { return equal(a.impl(), b.impl()); }
    140141inline bool operator==(const char* a, const AtomicString& b) { return b == a; }
  • trunk/Source/JavaScriptCore/wtf/text/StringImpl.cpp

    r91913 r94475  
    996996}
    997997
     998bool equal(const StringImpl* a, const UChar* b, unsigned length)
     999{
     1000    if (!a)
     1001        return !b;
     1002    if (!b)
     1003        return false;
     1004
     1005    if (a->length() != length)
     1006        return false;
     1007    // FIXME: perhaps we should have a more abstract macro that indicates when
     1008    // going 4 bytes at a time is unsafe
     1009#if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC)
     1010    const UChar* as = a->characters();
     1011    for (unsigned i = 0; i != length; ++i)
     1012        if (as[i] != b[i])
     1013            return false;
     1014    return true;
     1015#else
     1016    /* Do it 4-bytes-at-a-time on architectures where it's safe */
     1017   
     1018    const uint32_t* aCharacters = reinterpret_cast<const uint32_t*>(a->characters());
     1019    const uint32_t* bCharacters = reinterpret_cast<const uint32_t*>(b);
     1020   
     1021    unsigned halfLength = length >> 1;
     1022    for (unsigned i = 0; i != halfLength; ++i) {
     1023        if (*aCharacters++ != *bCharacters++)
     1024            return false;
     1025    }
     1026   
     1027    if (length & 1 &&  *reinterpret_cast<const uint16_t*>(aCharacters) != *reinterpret_cast<const uint16_t*>(bCharacters))
     1028        return false;
     1029   
     1030    return true;
     1031#endif
     1032}
     1033
    9981034bool equalIgnoringCase(StringImpl* a, StringImpl* b)
    9991035{
  • trunk/Source/JavaScriptCore/wtf/text/StringImpl.h

    r92569 r94475  
    348348bool equal(const StringImpl*, const char*);
    349349inline bool equal(const char* a, StringImpl* b) { return equal(b, a); }
     350bool equal(const StringImpl*, const UChar*, unsigned);
    350351
    351352bool equalIgnoringCase(StringImpl*, StringImpl*);
Note: See TracChangeset for help on using the changeset viewer.