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

Unified Diff: src/array.js

Issue 6173004: Simplify Join and speedup joining arrays of numbers. (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 6240)
+++ src/array.js (working copy)
@@ -117,19 +117,16 @@
// Fast case for one-element arrays.
if (length == 1) {
var e = array[0];
- if (!IS_UNDEFINED(e) || (0 in array)) {
- if (IS_STRING(e)) return e;
- return convert(e);
- }
- return '';
+ if (IS_STRING(e)) return e;
+ return convert(e);
}
// Construct an array for the 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) {
+ var elements_length = 0;
for (var i = 0; i < length; i++) {
var e = array[i];
if (!IS_UNDEFINED(e)) {
@@ -142,16 +139,25 @@
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)) {
+ // Non-empty separator case.
+ // If the first element is a number then use the heuristic that the
+ // remaining elements are also likely to be numbers.
+ if (!IS_NUMBER(array[0])) {
+ for (var i = 0; i < length; i++) {
+ var e = array[i];
if (!IS_STRING(e)) e = convert(e);
elements[i] = e;
- } else {
- elements[i] = '';
}
- }
+ } else {
+ for (var i = 0; i < length; i++) {
+ var e = array[i];
+ if (IS_NUMBER(e)) elements[i] = %_NumberToString(e);
+ else {
+ if (!IS_STRING(e)) e = convert(e);
+ elements[i] = e;
+ }
+ }
+ }
var result = %_FastAsciiArrayJoin(elements, separator);
if (!IS_UNDEFINED(result)) return result;
« 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