Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: src/string.js

Issue 518059: Make String.prototype.replace a tiny bit faster by avoiding... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string.js
===================================================================
--- src/string.js (revision 3553)
+++ src/string.js (working copy)
@@ -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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698