Commit 060711ab authored by kasperl@chromium.org's avatar kasperl@chromium.org

Improve the performance of String.prototype.concat and the slow-case

for compare operations.
Review URL: http://codereview.chromium.org/521054

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3553 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ba9b59d5
......@@ -114,30 +114,33 @@ function STRICT_EQUALS(x) {
// ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
// the result when either (or both) the operands are NaN.
function COMPARE(x, ncr) {
// Fast case for numbers and strings.
if (IS_NUMBER(this) && IS_NUMBER(x)) {
return %NumberCompare(this, x, ncr);
}
if (IS_STRING(this) && IS_STRING(x)) {
return %StringCompare(this, x);
}
var left;
// If one of the operands is undefined, it will convert to NaN and
// thus the result should be as if one of the operands was NaN.
if (IS_UNDEFINED(this) || IS_UNDEFINED(x)) {
// Fast cases for string, numbers and undefined compares.
if (IS_STRING(this)) {
if (IS_STRING(x)) return %StringCompare(this, x);
if (IS_UNDEFINED(x)) return ncr;
left = this;
} else if (IS_NUMBER(this)) {
if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
if (IS_UNDEFINED(x)) return ncr;
left = this;
} else if (IS_UNDEFINED(this)) {
return ncr;
} else {
if (IS_UNDEFINED(x)) return ncr;
left = %ToPrimitive(this, NUMBER_HINT);
}
// Default implementation.
var a = %ToPrimitive(this, NUMBER_HINT);
var b = %ToPrimitive(x, NUMBER_HINT);
if (IS_STRING(a) && IS_STRING(b)) {
return %StringCompare(a, b);
var right = %ToPrimitive(x, NUMBER_HINT);
if (IS_STRING(left) && IS_STRING(right)) {
return %StringCompare(left, right);
} else {
var a_number = %ToNumber(a);
var b_number = %ToNumber(b);
if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr;
return %NumberCompare(a_number, b_number, ncr);
var left_number = %ToNumber(left);
var right_number = %ToNumber(right);
if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
return %NumberCompare(left_number, right_number, ncr);
}
}
......
......@@ -87,12 +87,14 @@ function StringCharCodeAt(pos) {
// ECMA-262, section 15.5.4.6
function StringConcat() {
var len = %_ArgumentsLength();
var parts = new $Array(len + 1);
parts[0] = ToString(this);
for (var i = 0; i < len; i++)
parts[i + 1] = ToString(%_Arguments(i));
return parts.join('');
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);
}
return %StringBuilderConcat(parts, len, "");
}
// Match ES3 and Safari
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment