Changeset 43856 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
May 19, 2009, 1:01:22 AM (16 years ago)
Author:
[email protected]
Message:

2009-05-19 Maciej Stachowiak <[email protected]>

Reviewed by Gavin Barraclough.


  • speed up string comparison, especially for short strings


~1% on SunSpider

  • JavaScriptCore.exp:
  • runtime/UString.cpp:
  • runtime/UString.h: (JSC::operator==): Inline UString's operator==, since it is called from hot places in the runtime. Also, specialize 2-char strings in a similar way to 1-char, since we're taking the hit of a switch anyway.
Location:
trunk/JavaScriptCore/runtime
Files:
2 edited

Legend:

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

    r43457 r43856  
    15671567}
    15681568
    1569 bool operator==(const UString& s1, const UString& s2)
    1570 {
    1571     int size = s1.size();
    1572     switch (size) {
    1573         case 0:
    1574             return !s2.size();
    1575         case 1:
    1576             return s2.size() == 1 && s1.data()[0] == s2.data()[0];
    1577         default:
    1578             return s2.size() == size && memcmp(s1.data(), s2.data(), size * sizeof(UChar)) == 0;
    1579     }
    1580 }
    1581 
    15821569bool operator==(const UString& s1, const char *s2)
    15831570{
  • trunk/JavaScriptCore/runtime/UString.h

    r43339 r43856  
    356356    PassRefPtr<UString::Rep> concatenate(UString::Rep*, double);
    357357
    358     bool operator==(const UString&, const UString&);
     358    inline bool operator==(const UString& s1, const UString& s2)
     359    {
     360        int size = s1.size();
     361        switch (size) {
     362        case 0:
     363            return !s2.size();
     364        case 1:
     365            return s2.size() == 1 && s1.data()[0] == s2.data()[0];
     366        case 2: {
     367            if (s2.size() != 2)
     368                return false;
     369            const UChar* d1 = s1.data();
     370            const UChar* d2 = s2.data();
     371            return (d1[0] == d2[0]) & (d1[1] == d2[1]);
     372        }
     373        default:
     374            return s2.size() == size && memcmp(s1.data(), s2.data(), size * sizeof(UChar)) == 0;
     375        }
     376    }
     377
    359378
    360379    inline bool operator!=(const UString& s1, const UString& s2)
Note: See TracChangeset for help on using the changeset viewer.