OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
10 | 10 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 // We pull the empty separator check outside the loop for speed! | 138 // We pull the empty separator check outside the loop for speed! |
139 if (separator.length == 0) { | 139 if (separator.length == 0) { |
140 var elements_length = 0; | 140 var elements_length = 0; |
141 for (var i = 0; i < length; i++) { | 141 for (var i = 0; i < length; i++) { |
142 var e = array[i]; | 142 var e = array[i]; |
143 if (!IS_STRING(e)) e = convert(e); | 143 if (!IS_STRING(e)) e = convert(e); |
144 elements[elements_length++] = e; | 144 elements[elements_length++] = e; |
145 } | 145 } |
146 elements.length = elements_length; | 146 elements.length = elements_length; |
147 var result = %_FastAsciiArrayJoin(elements, ''); | 147 var result = %_FastOneByteArrayJoin(elements, ''); |
148 if (!IS_UNDEFINED(result)) return result; | 148 if (!IS_UNDEFINED(result)) return result; |
149 return %StringBuilderConcat(elements, elements_length, ''); | 149 return %StringBuilderConcat(elements, elements_length, ''); |
150 } | 150 } |
151 // Non-empty separator case. | 151 // Non-empty separator case. |
152 // If the first element is a number then use the heuristic that the | 152 // If the first element is a number then use the heuristic that the |
153 // remaining elements are also likely to be numbers. | 153 // remaining elements are also likely to be numbers. |
154 if (!IS_NUMBER(array[0])) { | 154 if (!IS_NUMBER(array[0])) { |
155 for (var i = 0; i < length; i++) { | 155 for (var i = 0; i < length; i++) { |
156 var e = array[i]; | 156 var e = array[i]; |
157 if (!IS_STRING(e)) e = convert(e); | 157 if (!IS_STRING(e)) e = convert(e); |
158 elements[i] = e; | 158 elements[i] = e; |
159 } | 159 } |
160 } else { | 160 } else { |
161 for (var i = 0; i < length; i++) { | 161 for (var i = 0; i < length; i++) { |
162 var e = array[i]; | 162 var e = array[i]; |
163 if (IS_NUMBER(e)) { | 163 if (IS_NUMBER(e)) { |
164 e = %_NumberToString(e); | 164 e = %_NumberToString(e); |
165 } else if (!IS_STRING(e)) { | 165 } else if (!IS_STRING(e)) { |
166 e = convert(e); | 166 e = convert(e); |
167 } | 167 } |
168 elements[i] = e; | 168 elements[i] = e; |
169 } | 169 } |
170 } | 170 } |
171 var result = %_FastAsciiArrayJoin(elements, separator); | 171 var result = %_FastOneByteArrayJoin(elements, separator); |
172 if (!IS_UNDEFINED(result)) return result; | 172 if (!IS_UNDEFINED(result)) return result; |
173 | 173 |
174 return %StringBuilderJoin(elements, length, separator); | 174 return %StringBuilderJoin(elements, length, separator); |
175 } finally { | 175 } finally { |
176 // Make sure to remove the last element of the visited array no | 176 // Make sure to remove the last element of the visited array no |
177 // matter what happens. | 177 // matter what happens. |
178 if (is_array) visited_arrays.length = visited_arrays.length - 1; | 178 if (is_array) visited_arrays.length = visited_arrays.length - 1; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); | 368 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); |
369 | 369 |
370 var array = TO_OBJECT_INLINE(this); | 370 var array = TO_OBJECT_INLINE(this); |
371 var length = TO_UINT32(array.length); | 371 var length = TO_UINT32(array.length); |
372 if (IS_UNDEFINED(separator)) { | 372 if (IS_UNDEFINED(separator)) { |
373 separator = ','; | 373 separator = ','; |
374 } else if (!IS_STRING(separator)) { | 374 } else if (!IS_STRING(separator)) { |
375 separator = NonStringToString(separator); | 375 separator = NonStringToString(separator); |
376 } | 376 } |
377 | 377 |
378 var result = %_FastAsciiArrayJoin(array, separator); | 378 var result = %_FastOneByteArrayJoin(array, separator); |
379 if (!IS_UNDEFINED(result)) return result; | 379 if (!IS_UNDEFINED(result)) return result; |
380 | 380 |
381 return Join(array, length, separator, ConvertToString); | 381 return Join(array, length, separator, ConvertToString); |
382 } | 382 } |
383 | 383 |
384 | 384 |
385 function ObservedArrayPop(n) { | 385 function ObservedArrayPop(n) { |
386 n--; | 386 n--; |
387 var value = this[n]; | 387 var value = this[n]; |
388 | 388 |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 )); | 1546 )); |
1547 | 1547 |
1548 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1548 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
1549 "join", getFunction("join", ArrayJoin), | 1549 "join", getFunction("join", ArrayJoin), |
1550 "pop", getFunction("pop", ArrayPop), | 1550 "pop", getFunction("pop", ArrayPop), |
1551 "push", getFunction("push", ArrayPush) | 1551 "push", getFunction("push", ArrayPush) |
1552 )); | 1552 )); |
1553 } | 1553 } |
1554 | 1554 |
1555 SetUpArray(); | 1555 SetUpArray(); |
OLD | NEW |