From 18f2ac65c3c168099b6b16a19c671dda63c3fa6f Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Fri, 13 Nov 2009 14:28:27 -0500 Subject: [PATCH] Optimize Element#immediateDescendants. --- CHANGELOG | 2 ++ src/dom/dom.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f1d99bf..31a86cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/src/dom/dom.js b/src/dom/dom.js index 6489c4f..9ba4659 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -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; }, /**