tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 91721a390fcffde5d6e7da27c98fbc3829ab6560
parent 38fe31e6d88fc15a3f332f248de9a19e6d2df17f
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Wed,  7 Jan 2026 14:42:30 +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:
Mdom/base/Element.h | 4++++
Mdom/base/nsIContent.h | 7-------
Mdom/base/nsIContentInlines.h | 8--------
Mdom/base/nsINode.cpp | 4----
Mdom/base/nsINode.h | 2+-
5 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/dom/base/Element.h b/dom/base/Element.h @@ -2582,6 +2582,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.