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

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 6231)
+++ src/array.js (working copy)
@@ -125,34 +125,45 @@
}
// 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)) {
+ if (!IS_UNDEFINED(e)) {
if (!IS_STRING(e)) e = convert(e);
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)) {
+ if (!IS_STRING(e)) e = convert(e);
+ elements[i] = e;
+ } else {
+ elements[i] = '';
}
}
- 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 j = length2;
+ var i = length;
+ elements[--j] = elements[--i];
+ while (i > 0) {
+ elements[--j] = separator;
+ elements[--j] = elements[--i];
+ }
+ return %StringBuilderConcat(elements, 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