Optimize Element#immediateDescendants.

This commit is contained in:
Juriy Zaytsev 2009-11-13 14:28:27 -05:00
parent 82c9b9c783
commit 18f2ac65c3
2 changed files with 10 additions and 4 deletions

View File

@ -1,3 +1,5 @@
* Optimize Element#immediateDescendants. (kangax, Tobie Langel)
* Remove unnecessary function object creation and `Number#times` in `Element._getContentFromAnonymousElement`. (kangax)
* Eliminate runtime forking and long method lookup in `Element.hasAttribute`. (kangax)

View File

@ -536,10 +536,14 @@ Element.Methods = {
* **This method is deprecated, please see [[Element.childElements]]**.
**/
immediateDescendants: function(element) {
if (!(element = $(element).firstChild)) return [];
while (element && element.nodeType != 1) element = element.nextSibling;
if (element) return [element].concat($(element).nextSiblings());
return [];
var results = [], child = $(element).firstChild;
while (child) {
if (child.nodeType === 1) {
results.push(Element.extend(child));
}
child = child.nextSibling;
}
return results;
},
/**