| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return ''; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Construct an array for the elements. | 127 // Construct an array for the elements. |
| 128 var elements; | 128 var elements = new $Array(length); |
| 129 var elements_length = 0; | 129 var elements_length = 0; |
| 130 | 130 |
| 131 // We pull the empty separator check outside the loop for speed! | 131 // We pull the empty separator check outside the loop for speed! |
| 132 if (separator.length == 0) { | 132 if (separator.length == 0) { |
| 133 elements = new $Array(length); | |
| 134 for (var i = 0; i < length; i++) { | 133 for (var i = 0; i < length; i++) { |
| 135 var e = array[i]; | 134 var e = array[i]; |
| 136 if (!IS_UNDEFINED(e) || (i in array)) { | 135 if (!IS_UNDEFINED(e)) { |
| 137 if (!IS_STRING(e)) e = convert(e); | 136 if (!IS_STRING(e)) e = convert(e); |
| 138 elements[elements_length++] = e; | 137 elements[elements_length++] = e; |
| 139 } | 138 } |
| 140 } | 139 } |
| 141 } else { | 140 elements.length = elements_length; |
| 142 elements = new $Array(length << 1); | 141 var result = %_FastAsciiArrayJoin(elements, ''); |
| 143 for (var i = 0; i < length; i++) { | 142 if (!IS_UNDEFINED(result)) return result; |
| 144 var e = array[i]; | 143 return %StringBuilderConcat(elements, elements_length, ''); |
| 145 if (i != 0) elements[elements_length++] = separator; | 144 } |
| 146 if (!IS_UNDEFINED(e) || (i in array)) { | 145 // Non-empty separator. |
| 147 if (!IS_STRING(e)) e = convert(e); | 146 for (var i = 0; i < length; i++) { |
| 148 elements[elements_length++] = e; | 147 var e = array[i]; |
| 149 } | 148 if (!IS_UNDEFINED(e)) { |
| 149 if (!IS_STRING(e)) e = convert(e); |
| 150 elements[i] = e; |
| 151 } else { |
| 152 elements[i] = ''; |
| 150 } | 153 } |
| 151 } | 154 } |
| 152 elements.length = elements_length; | 155 var result = %_FastAsciiArrayJoin(elements, separator); |
| 153 var result = %_FastAsciiArrayJoin(elements, ""); | 156 if (!IS_UNDEFINED(result)) return result; |
| 154 if (!IS_UNDEFINED(result)) return result; | 157 |
| 155 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, ''); |
| 156 } finally { | 167 } finally { |
| 157 // Make sure to pop the visited array no matter what happens. | 168 // Make sure to pop the visited array no matter what happens. |
| 158 if (is_array) visited_arrays.pop(); | 169 if (is_array) visited_arrays.pop(); |
| 159 } | 170 } |
| 160 } | 171 } |
| 161 | 172 |
| 162 | 173 |
| 163 function ConvertToString(x) { | 174 function ConvertToString(x) { |
| 164 // Assumes x is a non-string. | 175 // Assumes x is a non-string. |
| 165 if (IS_NUMBER(x)) return %_NumberToString(x); | 176 if (IS_NUMBER(x)) return %_NumberToString(x); |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1221 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1211 "reduce", getFunction("reduce", ArrayReduce, 1), | 1222 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1212 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1223 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1213 )); | 1224 )); |
| 1214 | 1225 |
| 1215 %FinishArrayPrototypeSetup($Array.prototype); | 1226 %FinishArrayPrototypeSetup($Array.prototype); |
| 1216 } | 1227 } |
| 1217 | 1228 |
| 1218 | 1229 |
| 1219 SetupArray(); | 1230 SetupArray(); |
| OLD | NEW |