Commit bf3b56fb authored by benjamin@webkit.org's avatar benjamin@webkit.org
Browse files

replaceUsingStringSearch: delay the creation of the replace string until needed

https://bugs.webkit.org/show_bug.cgi?id=83841

Patch by Benjamin Poulain <bpoulain@apple.com> on 2012-04-18
Reviewed by Geoffrey Garen.

We do not need to obtain the replaceValue until we have a match. By moving the intialization
of replaceValue when needed, we save a few instructions when there is no match.

* runtime/StringPrototype.cpp:
(JSC::replaceUsingRegExpSearch):
(JSC::replaceUsingStringSearch):
(JSC::stringProtoFuncReplace):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114521 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 021cace4
2012-04-18 Benjamin Poulain <bpoulain@apple.com>
replaceUsingStringSearch: delay the creation of the replace string until needed
https://bugs.webkit.org/show_bug.cgi?id=83841
Reviewed by Geoffrey Garen.
We do not need to obtain the replaceValue until we have a match. By moving the intialization
of replaceValue when needed, we save a few instructions when there is no match.
* runtime/StringPrototype.cpp:
(JSC::replaceUsingRegExpSearch):
(JSC::replaceUsingStringSearch):
(JSC::stringProtoFuncReplace):
2012-04-18 Mark Hahnenberg <mhahnenberg@apple.com>
 
GC activity timer should be tied to allocation, not collection
......@@ -441,8 +441,9 @@ static NEVER_INLINE EncodedJSValue removeUsingRegExpSearch(ExecState* exec, JSSt
return JSValue::encode(jsSpliceSubstrings(exec, string, source, sourceRanges.data(), sourceRanges.size()));
}
static NEVER_INLINE EncodedJSValue replaceUsingRegExpSearch(ExecState* exec, JSString* string, JSValue searchValue, JSValue replaceValue)
static NEVER_INLINE EncodedJSValue replaceUsingRegExpSearch(ExecState* exec, JSString* string, JSValue searchValue)
{
JSValue replaceValue = exec->argument(1);
UString replacementString;
CallData callData;
CallType callType = getCallData(replaceValue, callData);
......@@ -625,7 +626,7 @@ static NEVER_INLINE EncodedJSValue replaceUsingRegExpSearch(ExecState* exec, JSS
return JSValue::encode(jsSpliceSubstringsWithSeparators(exec, string, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size()));
}
static inline EncodedJSValue replaceUsingStringSearch(ExecState* exec, JSString* jsString, JSValue searchValue, JSValue replaceValue)
static inline EncodedJSValue replaceUsingStringSearch(ExecState* exec, JSString* jsString, JSValue searchValue)
{
const UString& string = jsString->value(exec);
UString searchString = searchValue.toUString(exec);
......@@ -650,6 +651,7 @@ static inline EncodedJSValue replaceUsingStringSearch(ExecState* exec, JSString*
if (matchStart == notFound)
return JSValue::encode(jsString);
JSValue replaceValue = exec->argument(1);
CallData callData;
CallType callType = getCallData(replaceValue, callData);
if (callType != CallTypeNone) {
......@@ -685,11 +687,10 @@ EncodedJSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec)
return throwVMTypeError(exec);
JSString* string = thisValue.toString(exec);
JSValue searchValue = exec->argument(0);
JSValue replaceValue = exec->argument(1);
if (searchValue.inherits(&RegExpObject::s_info))
return replaceUsingRegExpSearch(exec, string, searchValue, replaceValue);
return replaceUsingStringSearch(exec, string, searchValue, replaceValue);
return replaceUsingRegExpSearch(exec, string, searchValue);
return replaceUsingStringSearch(exec, string, searchValue);
}
EncodedJSValue JSC_HOST_CALL stringProtoFuncToString(ExecState* exec)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment