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

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,22 +117,19 @@
// 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);
Lasse Reichstein 2011/01/10 10:51:44 How about checking against undefined after the IS_
sandholm 2011/01/10 11:40:52 Doesn't matter.
}
// 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)) {
+ if (!(e == null)) {
Lasse Reichstein 2011/01/10 10:51:44 Use IS_NULL_OR_UNDEFINED (which reduces to this bu
sandholm 2011/01/10 11:40:52 I changed this back to IS_UNDEFINED after all.
if (!IS_STRING(e)) e = convert(e);
elements[elements_length++] = e;
}
@@ -143,15 +140,23 @@
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_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;
+ }
Lasse Reichstein 2011/01/10 10:51:44 How about: if (IS_NUMBER(e)) { e = %_NumberToSt
sandholm 2011/01/10 11:40:52 I want the expected path (IS_NUMBER) to be as fast
+ }
+ }
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