| OLD | NEW |
| 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 Loading... |
| 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 = new $Array(length); |
| 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 for (var i = 0; i < length; i++) { | 133 for (var i = 0; i < length; i++) { |
| 134 var e = array[i]; | 134 var e = array[i]; |
| 135 if (!IS_UNDEFINED(e) || (i in array)) { | 135 if (!IS_UNDEFINED(e)) { |
| 136 if (!IS_STRING(e)) e = convert(e); | 136 if (!IS_STRING(e)) e = convert(e); |
| 137 elements[elements_length++] = e; | 137 elements[elements_length++] = e; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 } else { | 140 elements.length = elements_length; |
| 141 elements = new $Array(length << 1); | 141 var result = %_FastAsciiArrayJoin(elements, ''); |
| 142 for (var i = 0; i < length; i++) { | 142 if (!IS_UNDEFINED(result)) return result; |
| 143 var e = array[i]; | 143 return %StringBuilderConcat(elements, elements_length, ''); |
| 144 if (i != 0) elements[elements_length++] = separator; | 144 } |
| 145 if (!IS_UNDEFINED(e) || (i in array)) { | 145 // Non-empty separator. |
| 146 if (!IS_STRING(e)) e = convert(e); | 146 for (var i = 0; i < length; i++) { |
| 147 elements[elements_length++] = e; | 147 var e = array[i]; |
| 148 } | 148 if (!IS_UNDEFINED(e)) { |
| 149 if (!IS_STRING(e)) e = convert(e); |
| 150 elements[i] = e; |
| 151 } else { |
| 152 elements[i] = ''; |
| 149 } | 153 } |
| 150 } | 154 } |
| 151 elements.length = elements_length; | 155 var result = %_FastAsciiArrayJoin(elements, separator); |
| 152 var result = %_FastAsciiArrayJoin(elements, ""); | 156 if (!IS_UNDEFINED(result)) return result; |
| 153 if (!IS_UNDEFINED(result)) return result; | 157 |
| 154 return %StringBuilderConcat(elements, elements_length, ''); | 158 var length2 = (length << 1) - 1; |
| 159 var j = length2; |
| 160 var i = length; |
| 161 elements[--j] = elements[--i]; |
| 162 while (i > 0) { |
| 163 elements[--j] = separator; |
| 164 elements[--j] = elements[--i]; |
| 165 } |
| 166 return %StringBuilderConcat(elements, length2, ''); |
| 155 } finally { | 167 } finally { |
| 156 // Make sure to pop the visited array no matter what happens. | 168 // Make sure to pop the visited array no matter what happens. |
| 157 if (is_array) visited_arrays.pop(); | 169 if (is_array) visited_arrays.pop(); |
| 158 } | 170 } |
| 159 } | 171 } |
| 160 | 172 |
| 161 | 173 |
| 162 function ConvertToString(x) { | 174 function ConvertToString(x) { |
| 163 if (IS_STRING(x)) return x; | 175 // Assumes x is a non-string. |
| 164 if (IS_NUMBER(x)) return %_NumberToString(x); | 176 if (IS_NUMBER(x)) return %_NumberToString(x); |
| 165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 177 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
| 166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); | 178 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); |
| 167 } | 179 } |
| 168 | 180 |
| 169 | 181 |
| 170 function ConvertToLocaleString(e) { | 182 function ConvertToLocaleString(e) { |
| 171 if (e == null) { | 183 if (e == null) { |
| 172 return ''; | 184 return ''; |
| 173 } else { | 185 } else { |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1221 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1210 "reduce", getFunction("reduce", ArrayReduce, 1), | 1222 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1211 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1223 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1212 )); | 1224 )); |
| 1213 | 1225 |
| 1214 %FinishArrayPrototypeSetup($Array.prototype); | 1226 %FinishArrayPrototypeSetup($Array.prototype); |
| 1215 } | 1227 } |
| 1216 | 1228 |
| 1217 | 1229 |
| 1218 SetupArray(); | 1230 SetupArray(); |
| OLD | NEW |