Title: [114521] trunk/Source/_javascript_Core
Revision
114521
Author
[email protected]
Date
2012-04-18 10:07:23 -0700 (Wed, 18 Apr 2012)

Log Message

replaceUsingStringSearch: delay the creation of the replace string until needed
https://bugs.webkit.org/show_bug.cgi?id=83841

Patch by Benjamin Poulain <[email protected]> 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (114520 => 114521)


--- trunk/Source/_javascript_Core/ChangeLog	2012-04-18 17:05:11 UTC (rev 114520)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-04-18 17:07:23 UTC (rev 114521)
@@ -1,3 +1,18 @@
+2012-04-18  Benjamin Poulain  <[email protected]>
+
+        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  <[email protected]>
 
         GC activity timer should be tied to allocation, not collection

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (114520 => 114521)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2012-04-18 17:05:11 UTC (rev 114520)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2012-04-18 17:07:23 UTC (rev 114521)
@@ -441,8 +441,9 @@
     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 @@
     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 @@
     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 @@
         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)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to