From 941359b2f76b7e8e0a2e582e507cae90d4e759f8 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Sun, 14 Oct 2007 11:12:08 +0000 Subject: [PATCH] Performance enhancements to . Closes #9464 --- CHANGELOG | 2 ++ src/array.js | 23 ++++++++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f7b8493..79b0dea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Performance enhancements to $A. Closes #9464. [Samuel Lebeau] + * Make Function#argumentNames work with named functions. Closes #9826. [Samuel Lebeau] * Add Object.isHash. [Tobie Langel] diff --git a/src/array.js b/src/array.js index db192be..499a42f 100644 --- a/src/array.js +++ b/src/array.js @@ -1,26 +1,19 @@ function $A(iterable) { if (!iterable) return []; if (iterable.toArray) return iterable.toArray(); - else { - var results = []; - for (var i = 0, length = iterable.length; i < length; i++) - results.push(iterable[i]); - return results; - } + var length = iterable.length, results = new Array(length); + while (length--) results[length] = iterable[length]; + return results; } if (Prototype.Browser.WebKit) { function $A(iterable) { if (!iterable) return []; - if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && - iterable.toArray) { - return iterable.toArray(); - } else { - var results = []; - for (var i = 0, length = iterable.length; i < length; i++) - results.push(iterable[i]); - return results; - } + if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && + iterable.toArray) return iterable.toArray(); + var length = iterable.length, results = new Array(length); + while (length--) results[length] = iterable[length]; + return results; } }