Performance enhancements to . Closes #9464

This commit is contained in:
Tobie Langel 2007-10-14 11:12:08 +00:00
parent 7dda50a7c9
commit 941359b2f7
2 changed files with 10 additions and 15 deletions

View File

@ -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]

View File

@ -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;
}
}