Optimize fromCharCode for smi argument(s) case.

Review URL: http://codereview.chromium.org/778005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4081 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
lrn@chromium.org 2010-03-10 11:13:02 +00:00
parent 5153477a3e
commit e9484a07a3

View File

@ -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);
}