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

Unified Diff: src/string.js

Issue 584006: Optimize concat for one argument (two if you count 'this'). (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 10 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 3813)
+++ src/string.js (working copy)
@@ -87,14 +87,18 @@
// ECMA-262, section 15.5.4.6
function StringConcat() {
- var len = %_ArgumentsLength() + 1;
- var parts = new $Array(len);
- parts[0] = IS_STRING(this) ? this : ToString(this);
- for (var i = 1; i < len; i++) {
- var part = %_Arguments(i - 1);
- parts[i] = IS_STRING(part) ? part : ToString(part);
+ var len = %_ArgumentsLength();
+ var this_as_string = IS_STRING(this) ? this : ToString(this);
+ if (len === 1) {
+ return this_as_string + %_Arguments(0);
}
- return %StringBuilderConcat(parts, len, "");
+ var parts = new $Array(len + 1);
+ parts[0] = this_as_string;
+ for (var i = 0; i < len; i++) {
+ var part = %_Arguments(i);
+ parts[i + 1] = IS_STRING(part) ? part : ToString(part);
+ }
+ return %StringBuilderConcat(parts, len + 1, "");
}
// Match ES3 and Safari
« 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