From: ager@chromium.org Date: Wed, 10 Sep 2008 09:37:34 +0000 (+0000) Subject: Avoid the creation of a string builder for joining one-element arrays. X-Git-Tag: upstream/4.7.83~25411 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1aa48bb98f901771af0886973efc5cf216467e44;p=platform%2Fupstream%2Fv8.git Avoid the creation of a string builder for joining one-element arrays. Review URL: http://codereview.chromium.org/1888 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@250 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/array.js b/src/array.js index 061283a..a62cf4d 100644 --- a/src/array.js +++ b/src/array.js @@ -111,6 +111,14 @@ function Join(array, length, separator, convert) { return SparseJoin(array, length, convert); } + // Fast case for one-element arrays. + if (length == 1) { + var e = array[0]; + if (!IS_UNDEFINED(e) || (0 in array)) { + return convert(e); + } + } + var builder = new StringBuilder(); for (var i = 0; i < length; i++) {