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

Unified Diff: src/array.js

Issue 6100005: Make better use of the %_FastAsciiArrayJoin function. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array.js
===================================================================
--- src/array.js (revision 6227)
+++ src/array.js (working copy)
@@ -125,12 +125,11 @@
}
// Construct an array for the elements.
- var elements;
+ var elements = new $Array(length);
var elements_length = 0;
// We pull the empty separator check outside the loop for speed!
if (separator.length == 0) {
- elements = new $Array(length);
for (var i = 0; i < length; i++) {
var e = array[i];
if (!IS_UNDEFINED(e) || (i in array)) {
@@ -138,21 +137,32 @@
elements[elements_length++] = e;
}
}
- } else {
- elements = new $Array(length << 1);
- for (var i = 0; i < length; i++) {
- var e = array[i];
- if (i != 0) elements[elements_length++] = separator;
- if (!IS_UNDEFINED(e) || (i in array)) {
- if (!IS_STRING(e)) e = convert(e);
- elements[elements_length++] = e;
- }
+ elements.length = elements_length;
+ var result = %_FastAsciiArrayJoin(elements, '');
+ if (!IS_UNDEFINED(result)) return result;
+ return %StringBuilderConcat(elements, elements_length, '');
+ }
+ // Non-empty separator.
+ for (var i = 0; i < length; i++) {
+ var e = array[i];
+ if (!IS_UNDEFINED(e) || (i in array)) {
Lasse Reichstein 2011/01/07 14:58:58 If all actually used convert functions convert und
sandholm 2011/01/08 12:49:52 Done.
+ if (!IS_STRING(e)) e = convert(e);
+ elements[i] = e;
+ } else {
+ elements[i] = '';
Lasse Reichstein 2011/01/07 14:58:58 Would it be slower to have a separate counter for
sandholm 2011/01/08 12:49:52 You need to know where the separator goes, hence a
}
}
- elements.length = elements_length;
- var result = %_FastAsciiArrayJoin(elements, "");
- if (!IS_UNDEFINED(result)) return result;
- return %StringBuilderConcat(elements, elements_length, '');
+ var result = %_FastAsciiArrayJoin(elements, separator);
+ if (!IS_UNDEFINED(result)) return result;
+
+ var length2 = (length << 1) - 1;
+ var elements2 = new $Array(length2);
+ elements2[0] = elements[0];
+ for (var i = 1, j = 1; i < length; i++) {
+ elements2[j++] = separator;
+ elements2[j++] = elements[i];
+ }
Lasse Reichstein 2011/01/07 14:58:58 If you run backwards, you could expand the array i
sandholm 2011/01/08 12:49:52 Done.
+ return %StringBuilderConcat(elements2, length2, '');
} finally {
// Make sure to pop the visited array no matter what happens.
if (is_array) visited_arrays.pop();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698