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

Side by Side Diff: src/array.js

Issue 5977013: Aviod double checking IS_STRING when joining arrays. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 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/v8natives.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return SparseJoin(array, length, convert); 114 return SparseJoin(array, length, convert);
115 } 115 }
116 116
117 // Fast case for one-element arrays. 117 // Fast case for one-element arrays.
118 if (length == 1) { 118 if (length == 1) {
119 var e = array[0]; 119 var e = array[0];
120 if (!IS_UNDEFINED(e) || (0 in array)) { 120 if (!IS_UNDEFINED(e) || (0 in array)) {
121 if (IS_STRING(e)) return e; 121 if (IS_STRING(e)) return e;
122 return convert(e); 122 return convert(e);
123 } 123 }
124 return '';
124 } 125 }
125 126
126 // Construct an array for the elements. 127 // Construct an array for the elements.
127 var elements; 128 var elements;
128 var elements_length = 0; 129 var elements_length = 0;
129 130
130 // We pull the empty separator check outside the loop for speed! 131 // We pull the empty separator check outside the loop for speed!
131 if (separator.length == 0) { 132 if (separator.length == 0) {
132 elements = new $Array(length); 133 elements = new $Array(length);
133 for (var i = 0; i < length; i++) { 134 for (var i = 0; i < length; i++) {
(...skipping 19 matching lines...) Expand all
153 if (!IS_UNDEFINED(result)) return result; 154 if (!IS_UNDEFINED(result)) return result;
154 return %StringBuilderConcat(elements, elements_length, ''); 155 return %StringBuilderConcat(elements, elements_length, '');
155 } finally { 156 } finally {
156 // Make sure to pop the visited array no matter what happens. 157 // Make sure to pop the visited array no matter what happens.
157 if (is_array) visited_arrays.pop(); 158 if (is_array) visited_arrays.pop();
158 } 159 }
159 } 160 }
160 161
161 162
162 function ConvertToString(x) { 163 function ConvertToString(x) {
163 if (IS_STRING(x)) return x; 164 // Assumes x is a non-string.
164 if (IS_NUMBER(x)) return %_NumberToString(x); 165 if (IS_NUMBER(x)) return %_NumberToString(x);
165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; 166 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); 167 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x));
167 } 168 }
168 169
169 170
170 function ConvertToLocaleString(e) { 171 function ConvertToLocaleString(e) {
171 if (e == null) { 172 if (e == null) {
172 return ''; 173 return '';
173 } else { 174 } else {
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1210 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1210 "reduce", getFunction("reduce", ArrayReduce, 1), 1211 "reduce", getFunction("reduce", ArrayReduce, 1),
1211 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) 1212 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
1212 )); 1213 ));
1213 1214
1214 %FinishArrayPrototypeSetup($Array.prototype); 1215 %FinishArrayPrototypeSetup($Array.prototype);
1215 } 1216 }
1216 1217
1217 1218
1218 SetupArray(); 1219 SetupArray();
OLDNEW
« no previous file with comments | « no previous file | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698