Index: src/array.js |
=================================================================== |
--- src/array.js (revision 3389) |
+++ src/array.js (working copy) |
@@ -77,7 +77,8 @@ |
var key = keys[i]; |
if (key != last_key) { |
var e = array[key]; |
- builder.add(convert(e)); |
+ if (typeof(e) !== 'string') e = convert(e); |
+ builder.add(e); |
last_key = key; |
} |
} |
@@ -114,18 +115,37 @@ |
if (length == 1) { |
var e = array[0]; |
if (!IS_UNDEFINED(e) || (0 in array)) { |
+ if (typeof(e) === 'string') return e; |
return convert(e); |
} |
} |
var builder = new StringBuilder(); |
- for (var i = 0; i < length; i++) { |
- var e = array[i]; |
- if (i != 0) builder.add(separator); |
- if (!IS_UNDEFINED(e) || (i in array)) { |
- builder.add(convert(e)); |
+ // We pull the empty separator check outside the loop for speed! |
+ if (separator.length == 0) { |
+ for (var i = 0; i < length; i++) { |
+ var e = array[i]; |
+ if (!IS_UNDEFINED(e) || (i in array)) { |
+ if (typeof(e) !== 'string') e = convert(e); |
+ if (e.length > 0) { |
+ var elements = builder.elements; |
+ elements[elements.length] = e; |
+ } |
+ } |
} |
+ } else { |
+ for (var i = 0; i < length; i++) { |
+ var e = array[i]; |
+ if (i != 0) builder.add(separator); |
+ if (!IS_UNDEFINED(e) || (i in array)) { |
+ if (typeof(e) !== 'string') e = convert(e); |
+ if (e.length > 0) { |
+ var elements = builder.elements; |
+ elements[elements.length] = e; |
+ } |
+ } |
+ } |
} |
return builder.generate(); |
} finally { |
@@ -136,12 +156,14 @@ |
function ConvertToString(e) { |
+ if (typeof(e) === 'string') return e; |
if (e == null) return ''; |
else return ToString(e); |
} |
function ConvertToLocaleString(e) { |
+ if (typeof(e) === 'string') return e; |
if (e == null) return ''; |
else { |
// e_obj's toLocaleString might be overwritten, check if it is a function. |