Changeset 59355 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
May 13, 2010, 2:36:54 AM (15 years ago)
Author:
[email protected]
Message:

2010-05-13 Maciej Stachowiak <[email protected]>

Reviewed by Mark Rowe.

Various JavaScript string optimizations
https://bugs.webkit.org/show_bug.cgi?id=39051

Approximately 1% SunSpider speedup.


  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncJoin): Remove branches from the hot code path by moving the first pass outside the loop, and duplicating the hot loop to extract the loop-invariant branch.
  • runtime/RegExp.cpp: (JSC::RegExp::match): resize ovector to 0 instead of clearing to avoid thrash in case of large matches.
  • runtime/RegExpConstructor.h: (JSC::RegExpConstructor::performMatch): Mark ALWAYS_INLINE to make the compiler respect our authority.
  • runtime/StringPrototype.cpp: (JSC::jsSpliceSubstringsWithSeparators): Inline. (JSC::stringProtoFuncSubstring): Rewrite boundary condition checks to reduce the number of floating point comparisons and branches.
Location:
trunk/JavaScriptCore/runtime
Files:
4 edited

Legend:

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

    r59339 r59355  
    272272    if (isJSArray(&exec->globalData(), thisObj)) {
    273273        JSArray* array = asArray(thisObj);
    274         for (; k < length; k++) {
    275             if (!array->canGetIndex(k))
    276                 break;
    277             if (k >= 1) {
    278                 if (separator.isNull())
    279                     strBuffer.append(',');
    280                 else
    281                     strBuffer.append(separator);
    282             }
     274
     275        if (length) {
     276            if (!array->canGetIndex(k))
     277                goto skipFirstLoop;
    283278            JSValue element = array->getIndex(k);
    284279            if (!element.isUndefinedOrNull())
    285280                strBuffer.append(element.toString(exec));
    286         }
    287     }
     281            k++;
     282        }
     283
     284        if (separator.isNull()) {
     285            for (; k < length; k++) {
     286                if (!array->canGetIndex(k))
     287                    break;
     288                strBuffer.append(',');
     289                JSValue element = array->getIndex(k);
     290                if (!element.isUndefinedOrNull())
     291                    strBuffer.append(element.toString(exec));
     292            }
     293        } else {
     294            for (; k < length; k++) {
     295                if (!array->canGetIndex(k))
     296                    break;
     297                strBuffer.append(separator);
     298                JSValue element = array->getIndex(k);
     299                if (!element.isUndefinedOrNull())
     300                    strBuffer.append(element.toString(exec));
     301            }
     302        }
     303    }
     304 skipFirstLoop:
    288305    for (; k < length; k++) {
    289306        if (k >= 1) {
  • trunk/JavaScriptCore/runtime/RegExp.cpp

    r55322 r59355  
    108108        startOffset = 0;
    109109    if (ovector)
    110         ovector->clear();
     110        ovector->resize(0);
    111111
    112112    if (static_cast<unsigned>(startOffset) > s.size() || s.isNull())
     
    132132        for (int j = 0; j < offsetVectorSize; ++j)
    133133            offsetVector[j] = -1;
    134 
    135134
    136135#if ENABLE(YARR_JIT)
  • trunk/JavaScriptCore/runtime/RegExpConstructor.h

    r54022 r59355  
    110110      e.g., RegExp.lastMatch and RegExp.leftParen.
    111111    */
    112     inline void RegExpConstructor::performMatch(RegExp* r, const UString& s, int startOffset, int& position, int& length, int** ovector)
     112    ALWAYS_INLINE void RegExpConstructor::performMatch(RegExp* r, const UString& s, int startOffset, int& position, int& length, int** ovector)
    113113    {
    114114        position = r->match(s, startOffset, &d->tempOvector());
  • trunk/JavaScriptCore/runtime/StringPrototype.cpp

    r59282 r59355  
    246246};
    247247
    248 JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, JSString* sourceVal, const UString& source, const StringRange* substringRanges, int rangeCount, const UString* separators, int separatorCount);
    249 JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, JSString* sourceVal, const UString& source, const StringRange* substringRanges, int rangeCount, const UString* separators, int separatorCount)
     248static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, JSString* sourceVal, const UString& source, const StringRange* substringRanges, int rangeCount, const UString* separators, int separatorCount)
    250249{
    251250    if (rangeCount == 1 && separatorCount == 0) {
     
    755754
    756755    double start = a0.toNumber(exec);
    757     double end = a1.toNumber(exec);
    758     if (isnan(start))
     756    double end;
     757    if (!(start >= 0)) // check for negative values or NaN
    759758        start = 0;
    760     if (isnan(end))
    761         end = 0;
    762     if (start < 0)
    763         start = 0;
    764     if (end < 0)
    765         end = 0;
    766     if (start > len)
     759    else if (start > len)
    767760        start = len;
    768     if (end > len)
    769         end = len;
    770761    if (a1.isUndefined())
    771762        end = len;
     763    else {
     764        end = a1.toNumber(exec);
     765        if (!(end >= 0)) // check for negative values or NaN
     766            end = 0;
     767        else if (end > len)
     768            end = len;
     769    }
    772770    if (start > end) {
    773771        double temp = end;
Note: See TracChangeset for help on using the changeset viewer.