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

Unified Diff: src/runtime.js

Issue 521054: Improve the performance of String.prototype.concat and the slow-case... (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 | src/string.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.js
===================================================================
--- src/runtime.js (revision 3550)
+++ src/runtime.js (working copy)
@@ -114,30 +114,33 @@
// 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);
}
}
« no previous file with comments | « no previous file | src/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698