Revision: 3558
Author: [email protected]
Date: Thu Jan  7 04:18:56 2010
Log: Make String.prototype.replace a tiny bit faster by avoiding
ToString conversions for strings.
Review URL: http://codereview.chromium.org/518059
http://code.google.com/p/v8/source/detail?r=3558

Modified:
 /branches/bleeding_edge/src/string.js

=======================================
--- /branches/bleeding_edge/src/string.js       Thu Jan  7 01:59:37 2010
+++ /branches/bleeding_edge/src/string.js       Thu Jan  7 04:18:56 2010
@@ -196,7 +196,7 @@

 // ECMA-262, section 15.5.4.11
 function StringReplace(search, replace) {
-  var subject = ToString(this);
+  var subject = IS_STRING(this) ? this : ToString(this);

   // Delegate to one of the regular expression variants if necessary.
   if (IS_REGEXP(search)) {
@@ -209,7 +209,7 @@
   }

   // Convert the search argument to a string and search for it.
-  search = ToString(search);
+  search = IS_STRING(search) ? search : ToString(search);
   var start = %StringIndexOf(subject, search, 0);
   if (start < 0) return subject;
   var end = start + search.length;
@@ -224,7 +224,8 @@
   } else {
     reusableMatchInfo[CAPTURE0] = start;
     reusableMatchInfo[CAPTURE1] = end;
- ExpandReplacement(ToString(replace), subject, reusableMatchInfo, builder);
+    if (!IS_STRING(replace)) replace = ToString(replace);
+    ExpandReplacement(replace, subject, reusableMatchInfo, builder);
   }

   // suffix
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to