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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // If anything else gets here, we just do simple identity check. 107 // If anything else gets here, we just do simple identity check.
108 // Objects (including functions), null, undefined and booleans were 108 // Objects (including functions), null, undefined and booleans were
109 // checked in the CompareStub, so there should be nothing left. 109 // checked in the CompareStub, so there should be nothing left.
110 return %_ObjectEquals(this, x) ? 0 : 1; 110 return %_ObjectEquals(this, x) ? 0 : 1;
111 } 111 }
112 112
113 113
114 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as 114 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
115 // the result when either (or both) the operands are NaN. 115 // the result when either (or both) the operands are NaN.
116 function COMPARE(x, ncr) { 116 function COMPARE(x, ncr) {
117 // Fast case for numbers and strings. 117 var left;
118 if (IS_NUMBER(this) && IS_NUMBER(x)) {
119 return %NumberCompare(this, x, ncr);
120 }
121 if (IS_STRING(this) && IS_STRING(x)) {
122 return %StringCompare(this, x);
123 }
124 118
125 // If one of the operands is undefined, it will convert to NaN and 119 // Fast cases for string, numbers and undefined compares.
126 // thus the result should be as if one of the operands was NaN. 120 if (IS_STRING(this)) {
127 if (IS_UNDEFINED(this) || IS_UNDEFINED(x)) { 121 if (IS_STRING(x)) return %StringCompare(this, x);
122 if (IS_UNDEFINED(x)) return ncr;
123 left = this;
124 } else if (IS_NUMBER(this)) {
125 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
126 if (IS_UNDEFINED(x)) return ncr;
127 left = this;
128 } else if (IS_UNDEFINED(this)) {
128 return ncr; 129 return ncr;
130 } else {
131 if (IS_UNDEFINED(x)) return ncr;
132 left = %ToPrimitive(this, NUMBER_HINT);
129 } 133 }
130 134
131 // Default implementation. 135 // Default implementation.
132 var a = %ToPrimitive(this, NUMBER_HINT); 136 var right = %ToPrimitive(x, NUMBER_HINT);
133 var b = %ToPrimitive(x, NUMBER_HINT); 137 if (IS_STRING(left) && IS_STRING(right)) {
134 if (IS_STRING(a) && IS_STRING(b)) { 138 return %StringCompare(left, right);
135 return %StringCompare(a, b);
136 } else { 139 } else {
137 var a_number = %ToNumber(a); 140 var left_number = %ToNumber(left);
138 var b_number = %ToNumber(b); 141 var right_number = %ToNumber(right);
139 if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr; 142 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
140 return %NumberCompare(a_number, b_number, ncr); 143 return %NumberCompare(left_number, right_number, ncr);
141 } 144 }
142 } 145 }
143 146
144 147
145 148
146 /* ----------------------------------- 149 /* -----------------------------------
147 - - - A r i t h m e t i c - - - 150 - - - A r i t h m e t i c - - -
148 ----------------------------------- 151 -----------------------------------
149 */ 152 */
150 153
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 throw %MakeTypeError('cannot_convert_to_primitive', []); 606 throw %MakeTypeError('cannot_convert_to_primitive', []);
604 } 607 }
605 608
606 609
607 // NOTE: Setting the prototype for Array must take place as early as 610 // NOTE: Setting the prototype for Array must take place as early as
608 // possible due to code generation for array literals. When 611 // possible due to code generation for array literals. When
609 // generating code for a array literal a boilerplate array is created 612 // generating code for a array literal a boilerplate array is created
610 // that is cloned when running the code. It is essiential that the 613 // that is cloned when running the code. It is essiential that the
611 // boilerplate gets the right prototype. 614 // boilerplate gets the right prototype.
612 %FunctionSetPrototype($Array, new $Array(0)); 615 %FunctionSetPrototype($Array, new $Array(0));
OLDNEW
« 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