Ignore:
Timestamp:
Feb 13, 2009, 8:16:50 AM (16 years ago)
Author:
Darin Adler
Message:

2009-02-12 Darin Adler <Darin Adler>

Reviewed by Oliver Hunt and Alexey Proskuryakov.

Speed up a couple string functions.

  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncIndexOf): Added a fast path for cases where the second argument is either missing or an integer. (JSC::stringProtoFuncBig): Use jsNontrivialString since the string is guaranteed to be 2 or more characters long. (JSC::stringProtoFuncSmall): Ditto. (JSC::stringProtoFuncBlink): Ditto. (JSC::stringProtoFuncBold): Ditto. (JSC::stringProtoFuncItalics): Ditto. (JSC::stringProtoFuncStrike): Ditto. (JSC::stringProtoFuncSub): Ditto. (JSC::stringProtoFuncSup): Ditto. (JSC::stringProtoFuncFontcolor): Ditto. (JSC::stringProtoFuncFontsize): Make the fast path Sam recently added even faster by avoiding all but the minimum memory allocation. (JSC::stringProtoFuncAnchor): Use jsNontrivialString. (JSC::stringProtoFuncLink): Added a fast path.
  • runtime/UString.cpp: (JSC::UString::find): Added a fast path for single-character search strings.
File:
1 edited

Legend:

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

    r40169 r40975  
    14201420int UString::find(const UString& f, int pos) const
    14211421{
     1422    int fsz = f.size();
     1423
     1424    if (pos < 0)
     1425        pos = 0;
     1426
     1427    if (fsz == 1) {
     1428        UChar ch = f[0];
     1429        const UChar* end = data() + size();
     1430        for (const UChar* c = data() + pos; c < end; c++) {
     1431            if (*c == ch)
     1432                return static_cast<int>(c - data());
     1433        }
     1434        return -1;
     1435    }
     1436
    14221437    int sz = size();
    1423     int fsz = f.size();
    14241438    if (sz < fsz)
    14251439        return -1;
    1426     if (pos < 0)
    1427         pos = 0;
    14281440    if (fsz == 0)
    14291441        return pos;
Note: See TracChangeset for help on using the changeset viewer.