Commit f9e150b7 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Speed up join on arrays.

Review URL: http://codereview.chromium.org/457021

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3391 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 64ecb69b
......@@ -77,7 +77,8 @@ function SparseJoin(array, len, convert) {
var key = keys[i];
if (key != last_key) {
var e = array[key];
builder.add(convert(e));
if (typeof(e) !== 'string') e = convert(e);
builder.add(e);
last_key = key;
}
}
......@@ -114,17 +115,36 @@ function Join(array, length, separator, convert) {
if (length == 1) {
var e = array[0];
if (!IS_UNDEFINED(e) || (0 in array)) {
if (typeof(e) === 'string') return e;
return convert(e);
}
}
var builder = new StringBuilder();
for (var i = 0; i < length; i++) {
var e = array[i];
if (i != 0) builder.add(separator);
if (!IS_UNDEFINED(e) || (i in array)) {
builder.add(convert(e));
// We pull the empty separator check outside the loop for speed!
if (separator.length == 0) {
for (var i = 0; i < length; i++) {
var e = array[i];
if (!IS_UNDEFINED(e) || (i in array)) {
if (typeof(e) !== 'string') e = convert(e);
if (e.length > 0) {
var elements = builder.elements;
elements[elements.length] = e;
}
}
}
} else {
for (var i = 0; i < length; i++) {
var e = array[i];
if (i != 0) builder.add(separator);
if (!IS_UNDEFINED(e) || (i in array)) {
if (typeof(e) !== 'string') e = convert(e);
if (e.length > 0) {
var elements = builder.elements;
elements[elements.length] = e;
}
}
}
}
return builder.generate();
......@@ -136,12 +156,14 @@ function Join(array, length, separator, convert) {
function ConvertToString(e) {
if (typeof(e) === 'string') return e;
if (e == null) return '';
else return ToString(e);
}
function ConvertToLocaleString(e) {
if (typeof(e) === 'string') return e;
if (e == null) return '';
else {
// e_obj's toLocaleString might be overwritten, check if it is a function.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment