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

Side by Side Diff: src/js/array.js

Issue 2149303003: Revert "Make toLocaleString on arrays always call toLocaleString on its elements." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | test/mjsunit/array-tostring.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 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 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (separator === '') { 144 if (separator === '') {
145 if (keys.length === 0) return ''; 145 if (keys.length === 0) return '';
146 return SparseJoin(array, keys, convert); 146 return SparseJoin(array, keys, convert);
147 } else { 147 } else {
148 return SparseJoinWithSeparatorJS(array, keys, length, convert, separator); 148 return SparseJoinWithSeparatorJS(array, keys, length, convert, separator);
149 } 149 }
150 } 150 }
151 151
152 // Fast case for one-element arrays. 152 // Fast case for one-element arrays.
153 if (length === 1) { 153 if (length === 1) {
154 return convert(array[0]); 154 var e = array[0];
155 return IS_STRING(e) ? e : convert(e);
155 } 156 }
156 157
157 // Construct an array for the elements. 158 // Construct an array for the elements.
158 var elements = new InternalArray(length); 159 var elements = new InternalArray(length);
159 160
160 // We pull the empty separator check outside the loop for speed! 161 // We pull the empty separator check outside the loop for speed!
161 if (separator === '') { 162 if (separator === '') {
162 for (var i = 0; i < length; i++) { 163 for (var i = 0; i < length; i++) {
163 elements[i] = convert(array[i]); 164 var e = array[i];
165 elements[i] = IS_STRING(e) ? e : convert(e);
164 } 166 }
165 return %StringBuilderConcat(elements, length, ''); 167 return %StringBuilderConcat(elements, length, '');
166 } 168 }
167 // Non-empty separator case. 169 // Non-empty separator case.
168 elements[0] = convert(array[0]); 170 // If the first element is a number then use the heuristic that the
169 for (var i = 1; i < length; i++) { 171 // remaining elements are also likely to be numbers.
170 elements[i] = convert(array[i]); 172 var e = array[0];
173 if (IS_NUMBER(e)) {
174 elements[0] = %_NumberToString(e);
175 for (var i = 1; i < length; i++) {
176 e = array[i];
177 if (IS_NUMBER(e)) {
178 elements[i] = %_NumberToString(e);
179 } else {
180 elements[i] = IS_STRING(e) ? e : convert(e);
181 }
182 }
183 } else {
184 elements[0] = IS_STRING(e) ? e : convert(e);
185 for (var i = 1; i < length; i++) {
186 e = array[i];
187 elements[i] = IS_STRING(e) ? e : convert(e);
188 }
171 } 189 }
172 return %StringBuilderJoin(elements, length, separator); 190 return %StringBuilderJoin(elements, length, separator);
173 } 191 }
174 192
175 function Join(array, length, separator, convert) { 193 function Join(array, length, separator, convert) {
176 if (length === 0) return ''; 194 if (length === 0) return '';
177 195
178 var is_array = IS_ARRAY(array); 196 var is_array = IS_ARRAY(array);
179 197
180 if (is_array) { 198 if (is_array) {
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 %InstallToContext([ 1778 %InstallToContext([
1761 "array_pop", ArrayPop, 1779 "array_pop", ArrayPop,
1762 "array_push", ArrayPush, 1780 "array_push", ArrayPush,
1763 "array_shift", ArrayShift, 1781 "array_shift", ArrayShift,
1764 "array_splice", ArraySplice, 1782 "array_splice", ArraySplice,
1765 "array_slice", ArraySlice, 1783 "array_slice", ArraySlice,
1766 "array_unshift", ArrayUnshift, 1784 "array_unshift", ArrayUnshift,
1767 ]); 1785 ]);
1768 1786
1769 }); 1787 });
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/array-tostring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698