Changeset 60332 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
May 27, 2010, 4:43:54 PM (15 years ago)
Author:
[email protected]
Message:

2010-05-27 Luiz Agostini <[email protected]>

Reviewed by Darin Adler.

UTF-16 code points compare() for String objects
https://bugs.webkit.org/show_bug.cgi?id=39701

Moving compare() implementation from UString to StringImpl for it to be shared
with String. Adding overloaded free functions codePointCompare() in StringImpl
and WTFString. Renaming function compare in UString to codePointCompare to be
consistent.

  • runtime/JSArray.cpp: (JSC::compareByStringPairForQSort):
  • runtime/UString.cpp:
  • runtime/UString.h: (JSC::codePointCompare):
  • wtf/text/StringImpl.cpp: (WebCore::codePointCompare):
  • wtf/text/StringImpl.h:
  • wtf/text/WTFString.cpp: (WebCore::codePointCompare):
  • wtf/text/WTFString.h:
Location:
trunk/JavaScriptCore/runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSArray.cpp

    r55262 r60332  
    650650    const ValueStringPair* va = static_cast<const ValueStringPair*>(a);
    651651    const ValueStringPair* vb = static_cast<const ValueStringPair*>(b);
    652     return compare(va->second, vb->second);
     652    return codePointCompare(va->second, vb->second);
    653653}
    654654
  • trunk/JavaScriptCore/runtime/UString.cpp

    r60328 r60332  
    581581}
    582582
    583 int compare(const UString& s1, const UString& s2)
    584 {
    585     const unsigned l1 = s1.size();
    586     const unsigned l2 = s2.size();
    587     const unsigned lmin = l1 < l2 ? l1 : l2;
    588     const UChar* c1 = s1.data();
    589     const UChar* c2 = s2.data();
    590     unsigned l = 0;
    591     while (l < lmin && *c1 == *c2) {
    592         c1++;
    593         c2++;
    594         l++;
    595     }
    596 
    597     if (l < lmin)
    598         return (c1[0] > c2[0]) ? 1 : -1;
    599 
    600     if (l1 == l2)
    601         return 0;
    602 
    603     return (l1 > l2) ? 1 : -1;
    604 }
    605 
    606583CString UString::UTF8String(bool strict) const
    607584{
  • trunk/JavaScriptCore/runtime/UString.h

    r59337 r60332  
    203203    }
    204204
    205     int compare(const UString&, const UString&);
     205    inline int codePointCompare(const UString& s1, const UString& s2)
     206    {
     207        return codePointCompare(s1.rep(), s2.rep());
     208    }
    206209
    207210    // Rule from ECMA 15.2 about what an array index is.
Note: See TracChangeset for help on using the changeset viewer.