Bug 1596465 - Remove GetBindingParent() usage from nsINode::Contains. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 15 Nov 2019 12:32:37 +0000
changeset 502184 f5b772f54a1874b92274e8eab74f929db6346747
parent 502183 f22a913450cb3f5fd722b7864429fb12554a41bd
child 502185 5d471a86dc2963fadc67d4d37e03e8674289dbec
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1596465
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1596465 - Remove GetBindingParent() usage from nsINode::Contains. r=smaug And make ShadowRoot.contains() and checking nodes from different shadow trees faster. Differential Revision: https://phabricator.services.mozilla.com/D53037
dom/base/nsINode.cpp
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -2550,39 +2550,57 @@ void nsINode::AddSizeOfIncludingThis(nsW
   *aNodeSize += aSizes.mState.mMallocSizeOf(this);
   AddSizeOfExcludingThis(aSizes, aNodeSize);
 }
 
 bool nsINode::Contains(const nsINode* aOther) const {
   if (aOther == this) {
     return true;
   }
+
   if (!aOther || OwnerDoc() != aOther->OwnerDoc() ||
       IsInUncomposedDoc() != aOther->IsInUncomposedDoc() ||
-      !aOther->IsContent() || !GetFirstChild()) {
+      !aOther->IsContent() || !HasChildren()) {
     return false;
   }
 
-  const nsIContent* other = static_cast<const nsIContent*>(aOther);
-  if (this == OwnerDoc()) {
+  if (IsDocument()) {
     // document.contains(aOther) returns true if aOther is in the document,
     // but is not in any anonymous subtree.
     // IsInUncomposedDoc() check is done already before this.
-    return !other->IsInAnonymousSubtree();
+    return !aOther->IsInAnonymousSubtree();
   }
 
   if (!IsElement() && !IsDocumentFragment()) {
     return false;
   }
 
-  if (AsContent()->GetBindingParent() != other->GetBindingParent()) {
+  if (IsInShadowTree() != aOther->IsInShadowTree() ||
+      IsInNativeAnonymousSubtree() != aOther->IsInNativeAnonymousSubtree()) {
     return false;
   }
 
-  return other->IsInclusiveDescendantOf(this);
+  if (IsInNativeAnonymousSubtree()) {
+    if (GetClosestNativeAnonymousSubtreeRoot() !=
+        aOther->GetClosestNativeAnonymousSubtreeRoot()) {
+      return false;
+    }
+  }
+
+  if (IsInShadowTree()) {
+    ShadowRoot* otherRoot = aOther->GetContainingShadow();
+    if (IsShadowRoot()) {
+      return otherRoot == this;
+    }
+    if (otherRoot != GetContainingShadow()) {
+      return false;
+    }
+  }
+
+  return aOther->IsInclusiveDescendantOf(this);
 }
 
 uint32_t nsINode::Length() const {
   switch (NodeType()) {
     case DOCUMENT_TYPE_NODE:
       return 0;
 
     case TEXT_NODE: