commit d70ecb63797300988864902b029ea2ba333dd142
parent 87737acc9eebab9a034dadbd278d73d49357d69e
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Thu, 8 Jan 2026 10:26:04 +0000
Bug 2008949 - Make nsINode::GetShadowRoot faster. r=dom-core,smaug
Noticed this while looking at bug 2008590.
Right now nsINode::GetShadowRoot() goes through
nsIContent::GetShadowRoot() just to check the IsElement() flag.
Just move nsIContent::GetShadowRoot's implementation down to nsINode.
Differential Revision: https://phabricator.services.mozilla.com/D278123
Diffstat:
5 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/dom/base/Element.h b/dom/base/Element.h
@@ -2482,6 +2482,10 @@ inline mozilla::dom::Element* nsINode::GetPreviousElementSibling() const {
return nullptr;
}
+inline mozilla::dom::ShadowRoot* nsINode::GetShadowRoot() const {
+ return IsElement() ? AsElement()->GetShadowRoot() : nullptr;
+}
+
inline mozilla::dom::Element* nsINode::GetAsElementOrParentElement() const {
return IsElement() ? const_cast<mozilla::dom::Element*>(AsElement())
: GetParentElement();
diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h
@@ -301,13 +301,6 @@ class nsIContent : public nsINode {
virtual IMEState GetDesiredIMEState();
/**
- * Gets the ShadowRoot binding for this element.
- *
- * @return The ShadowRoot currently bound to this element.
- */
- inline mozilla::dom::ShadowRoot* GetShadowRoot() const;
-
- /**
* Gets the root of the node tree for this content if it is in a shadow tree.
*
* @return The ShadowRoot that is the root of the node tree.
diff --git a/dom/base/nsIContentInlines.h b/dom/base/nsIContentInlines.h
@@ -48,14 +48,6 @@ inline void nsIContent::SetPrimaryFrame(nsIFrame* aFrame) {
mPrimaryFrame = aFrame;
}
-inline mozilla::dom::ShadowRoot* nsIContent::GetShadowRoot() const {
- if (!IsElement()) {
- return nullptr;
- }
-
- return AsElement()->GetShadowRoot();
-}
-
template <nsINode::FlattenedParentType aType>
static inline nsINode* GetFlattenedTreeParentNode(const nsINode* aNode) {
if (!aNode->IsContent()) {
diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp
@@ -4149,10 +4149,6 @@ void nsINode::NotifyDevToolsOfRemovalsOfChildren() {
}
}
-ShadowRoot* nsINode::GetShadowRoot() const {
- return IsContent() ? AsContent()->GetShadowRoot() : nullptr;
-}
-
ShadowRoot* nsINode::GetShadowRootForSelection() const {
if (!StaticPrefs::dom_shadowdom_selection_across_boundary_enabled()) {
return nullptr;
diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h
@@ -2279,7 +2279,7 @@ class nsINode : public mozilla::dom::EventTarget {
ClearBoolFlag(ElementCreatedFromPrototypeAndHasUnmodifiedL10n);
}
- mozilla::dom::ShadowRoot* GetShadowRoot() const;
+ inline mozilla::dom::ShadowRoot* GetShadowRoot() const;
// Return the shadow root of the node if it is a shadow host and
// it meets the requirements for being a shadow host of a selection.