From 8d6acba9761c961f7245605e40bc9e5d72f8cd10 Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Tue, 17 Jul 2007 18:50:18 -0700 Subject: [PATCH] Avoid IndexOf calls while walking up the tree in FindForm(). Bug 388386, r+sr=jst --- .../html/content/src/nsGenericHTMLElement.cpp | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 3e8c57147dee..6b56cd33e450 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1231,11 +1231,17 @@ nsGenericHTMLElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent) already_AddRefed nsGenericHTMLElement::FindForm(nsIForm* aCurrentForm) { + // Make sure we don't end up finding a form that's anonymous from + // our point of view. + nsIContent* bindingParent = GetBindingParent(); + nsIContent* content = this; - while (content) { + while (content != bindingParent && content) { // If the current ancestor is a form, return it as our form if (content->Tag() == nsGkAtoms::form && content->IsNodeOfType(nsINode::eHTML)) { + NS_ASSERTION(nsContentUtils::IsInSameAnonymousTree(this, content), + "Walked too far?"); nsIDOMHTMLFormElement* form; CallQueryInterface(content, &form); @@ -1267,18 +1273,6 @@ nsGenericHTMLElement::FindForm(nsIForm* aCurrentForm) } } while (iter); } - - if (content) { - PRInt32 i = content->IndexOf(prevContent); - - if (i < 0) { - // This means 'prevContent' is anonymous content, form controls in - // anonymous content can't refer to the real form, if they do - // they end up in form.elements n' such, and that's wrong... - - return nsnull; - } - } } return nsnull;