Index: src/js/array.js |
diff --git a/src/js/array.js b/src/js/array.js |
index 2fde9fb3d4b3ae3f4d9f3abc849537c7f63fb339..c29b8f7256ad1d2c568f5a5103d4c666f4aaf485 100644 |
--- a/src/js/array.js |
+++ b/src/js/array.js |
@@ -151,7 +151,8 @@ function DoJoin(array, length, is_array, separator, convert) { |
// Fast case for one-element arrays. |
if (length === 1) { |
- return convert(array[0]); |
+ var e = array[0]; |
+ return IS_STRING(e) ? e : convert(e); |
} |
// Construct an array for the elements. |
@@ -160,14 +161,31 @@ function DoJoin(array, length, is_array, separator, convert) { |
// We pull the empty separator check outside the loop for speed! |
if (separator === '') { |
for (var i = 0; i < length; i++) { |
- elements[i] = convert(array[i]); |
+ var e = array[i]; |
+ elements[i] = IS_STRING(e) ? e : convert(e); |
} |
return %StringBuilderConcat(elements, length, ''); |
} |
// Non-empty separator case. |
- elements[0] = convert(array[0]); |
- for (var i = 1; i < length; i++) { |
- elements[i] = convert(array[i]); |
+ // If the first element is a number then use the heuristic that the |
+ // remaining elements are also likely to be numbers. |
+ var e = array[0]; |
+ if (IS_NUMBER(e)) { |
+ elements[0] = %_NumberToString(e); |
+ for (var i = 1; i < length; i++) { |
+ e = array[i]; |
+ if (IS_NUMBER(e)) { |
+ elements[i] = %_NumberToString(e); |
+ } else { |
+ elements[i] = IS_STRING(e) ? e : convert(e); |
+ } |
+ } |
+ } else { |
+ elements[0] = IS_STRING(e) ? e : convert(e); |
+ for (var i = 1; i < length; i++) { |
+ e = array[i]; |
+ elements[i] = IS_STRING(e) ? e : convert(e); |
+ } |
} |
return %StringBuilderJoin(elements, length, separator); |
} |