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

Unified Diff: src/string.js

Issue 778005: Optimize fromCharCode for smi argument(s) case. (Closed)
Patch Set: Created 10 years, 9 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
diff --git a/src/string.js b/src/string.js
index 067578c1414d0e422e17b19354f9ae1497b69304..9547900a2b782b0401d4ebcac977feb1eaec27b0 100644
--- a/src/string.js
+++ b/src/string.js
@@ -719,16 +719,26 @@ function StringTrimRight() {
return %StringTrim(TO_STRING_INLINE(this), false, true);
}
+var static_charcode_array = new $Array(4);
+
// ECMA-262, section 15.5.3.2
function StringFromCharCode(code) {
var n = %_ArgumentsLength();
- if (n == 1) return %_CharFromCode(ToNumber(code) & 0xffff)
+ if (n == 1) {
+ if (!%_IsSmi(code)) code = ToNumber(code);
+ return %_CharFromCode(code & 0xffff);
+ }
// NOTE: This is not super-efficient, but it is necessary because we
// want to avoid converting to numbers from within the virtual
// machine. Maybe we can find another way of doing this?
- var codes = new $Array(n);
- for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i));
+ var codes = static_charcode_array;
+ for (var i = 0; i < n; i++) {
+ var code = %_Arguments(i);
+ if (!%_IsSmi(code)) code = ToNumber(code);
+ codes[i] = code;
+ }
+ codes.length = n;
return %StringFromCharCodeArray(codes);
}
« 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