From 2932c886ad0e5792ea46fa0c2f2727eb485b863d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 22 Mar 2012 00:10:51 -0400 Subject: [PATCH] Bug 700981 part 4. Add a fast-path to IsAllowedAsChild for the case of a child that has no kids. r=smaug --- content/base/src/nsGenericElement.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 072467c1d589..9a211eb84661 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -4030,7 +4030,14 @@ bool IsAllowedAsChild(nsIContent* aNewChild, nsINode* aParent, "Nodes that are not documents, document fragments or " "elements can't be parents!"); - if (aParent && nsContentUtils::ContentIsDescendantOf(aParent, aNewChild)) { + // A common case is that aNewChild has no kids, in which case + // aParent can't be a descendant of aNewChild unless they're + // actually equal to each other. Fast-path that case, since aParent + // could be pretty deep in the DOM tree. + if (aParent && + (aNewChild == aParent || + (aNewChild->GetFirstChild() && + nsContentUtils::ContentIsDescendantOf(aParent, aNewChild)))) { return false; }