Ignore:
Timestamp:
Mar 1, 2016, 3:35:05 PM (9 years ago)
Author:
[email protected]
Message:

FTL should simplify StringReplace with an empty replacement string
https://bugs.webkit.org/show_bug.cgi?id=154871

Reviewed by Michael Saboff.

This is a simple and hugely profitable change. If we do a string.replace(/things/, ""), then
this calls directly into StringPrototype's replace-with-empty-string logic instead of going
through stuff that does checks before reaching that same conclusion.

This speeds up Octane/regexp by about 6-10%. It also speeds up the attached microbenchmark by
about 7%.

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileStringReplace):

  • runtime/StringPrototype.cpp:

(JSC::jsSpliceSubstringsWithSeparators):
(JSC::removeUsingRegExpSearch):
(JSC::replaceUsingRegExpSearch):
(JSC::operationStringProtoFuncReplaceRegExpEmptyStr):
(JSC::operationStringProtoFuncReplaceRegExpString):

  • runtime/StringPrototype.h:
Location:
trunk/Source/JavaScriptCore/runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r197408 r197416  
    447447}
    448448
    449 static NEVER_INLINE EncodedJSValue removeUsingRegExpSearch(ExecState* exec, JSString* string, const String& source, RegExp* regExp)
     449static ALWAYS_INLINE EncodedJSValue removeUsingRegExpSearch(ExecState* exec, JSString* string, const String& source, RegExp* regExp)
    450450{
    451451    size_t lastIndex = 0;
     
    507507    }
    508508
     509    // FIXME: This is wrong because we may be called directly from the FTL.
     510    // https://bugs.webkit.org/show_bug.cgi?id=154874
    509511    RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
    510512
     
    663665
    664666    return JSValue::encode(jsSpliceSubstringsWithSeparators(exec, string, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size()));
     667}
     668
     669EncodedJSValue JIT_OPERATION operationStringProtoFuncReplaceRegExpEmptyStr(
     670    ExecState* exec, JSString* thisValue, RegExpObject* searchValue)
     671{
     672    RegExp* regExp = searchValue->regExp();
     673    if (regExp->global()) {
     674        // ES5.1 15.5.4.10 step 8.a.
     675        searchValue->setLastIndex(exec, 0);
     676        if (exec->hadException())
     677            return JSValue::encode(jsUndefined());
     678        return removeUsingRegExpSearch(exec, thisValue, thisValue->value(exec), regExp);
     679    }
     680
     681    CallData callData;
     682    String replacementString = emptyString();
     683    return replaceUsingRegExpSearch(
     684        exec, thisValue, searchValue, callData, CallTypeNone, replacementString, JSValue());
    665685}
    666686
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.h

    r197408 r197416  
    5555
    5656EncodedJSValue JIT_OPERATION operationStringProtoFuncReplaceGeneric(
    57     ExecState* exec, EncodedJSValue thisValue, EncodedJSValue searchValue,
    58     EncodedJSValue replaceValue);
     57    ExecState*, EncodedJSValue thisValue, EncodedJSValue searchValue, EncodedJSValue replaceValue);
     58
     59EncodedJSValue JIT_OPERATION operationStringProtoFuncReplaceRegExpEmptyStr(
     60    ExecState*, JSString* thisValue, RegExpObject* searchValue);
    5961
    6062EncodedJSValue JIT_OPERATION operationStringProtoFuncReplaceRegExpString(
    61     ExecState* exec, JSString* thisValue, RegExpObject* searchValue, JSString* replaceValue);
     63    ExecState*, JSString* thisValue, RegExpObject* searchValue, JSString* replaceValue);
    6264
    6365} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.