Changeset 60332 in webkit


Ignore:
Timestamp:
May 27, 2010 4:43:54 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-05-27 Luiz Agostini <luiz.agostini@openbossa.org>

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
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r60328 r60332  
     12010-05-27  Luiz Agostini  <luiz.agostini@openbossa.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        UTF-16 code points compare() for String objects
     6        https://bugs.webkit.org/show_bug.cgi?id=39701
     7
     8        Moving compare() implementation from UString to StringImpl for it to be shared
     9        with String. Adding overloaded free functions codePointCompare() in StringImpl
     10        and WTFString. Renaming function compare in UString to codePointCompare to be
     11        consistent.
     12
     13        * runtime/JSArray.cpp:
     14        (JSC::compareByStringPairForQSort):
     15        * runtime/UString.cpp:
     16        * runtime/UString.h:
     17        (JSC::codePointCompare):
     18        * wtf/text/StringImpl.cpp:
     19        (WebCore::codePointCompare):
     20        * wtf/text/StringImpl.h:
     21        * wtf/text/WTFString.cpp:
     22        (WebCore::codePointCompare):
     23        * wtf/text/WTFString.h:
     24
    1252010-05-26  Darin Adler  <darin@apple.com>
    226
  • 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.
  • trunk/JavaScriptCore/wtf/text/StringImpl.cpp

    r59969 r60332  
    477477}
    478478
     479int codePointCompare(const StringImpl* s1, const StringImpl* s2)
     480{
     481    const unsigned l1 = s1 ? s1->length() : 0;
     482    const unsigned l2 = s2 ? s2->length() : 0;
     483    const unsigned lmin = l1 < l2 ? l1 : l2;
     484    const UChar* c1 = s1 ? s1->characters() : 0;
     485    const UChar* c2 = s2 ? s2->characters() : 0;
     486    unsigned pos = 0;
     487    while (pos < lmin && *c1 == *c2) {
     488        c1++;
     489        c2++;
     490        pos++;
     491    }
     492
     493    if (pos < lmin)
     494        return (c1[0] > c2[0]) ? 1 : -1;
     495
     496    if (l1 == l2)
     497        return 0;
     498
     499    return (l1 > l2) ? 1 : -1;
     500}
     501
    479502int StringImpl::find(const char* chs, int index, bool caseSensitive)
    480503{
  • trunk/JavaScriptCore/wtf/text/StringImpl.h

    r59358 r60332  
    353353bool equalIgnoringNullity(StringImpl*, StringImpl*);
    354354
     355int codePointCompare(const StringImpl*, const StringImpl*);
     356
    355357static inline bool isSpaceOrNewline(UChar c)
    356358{
  • trunk/JavaScriptCore/wtf/text/WTFString.cpp

    r59196 r60332  
    127127}
    128128
     129int codePointCompare(const String& a, const String& b)
     130{
     131    return codePointCompare(a.impl(), b.impl());
     132}
     133
    129134void String::insert(const String& str, unsigned pos)
    130135{
  • trunk/JavaScriptCore/wtf/text/WTFString.h

    r59202 r60332  
    352352}
    353353
     354int codePointCompare(const String&, const String&);
     355
    354356inline int find(const UChar* characters, size_t length, UChar character, int startPosition)
    355357{
Note: See TracChangeset for help on using the changeset viewer.