From 1918c1c2034ca0ac75744bfa08c53ddfc8fb1caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 May 2023 10:03:20 +0200 Subject: [PATCH] style: Inline GeckoNode::prev_sibling It's very hot when matching some kind of selectors like the ones in bug 1717267, and the two function calls show up in the profiles. Differential Revision: https://phabricator.services.mozilla.com/D119505 --- components/style/dom.rs | 2 +- components/style/gecko/wrapper.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/style/dom.rs b/components/style/dom.rs index c70a8fd26be..c85ff1edaff 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -151,7 +151,7 @@ pub trait TNode: Sized + Copy + Clone + Debug + NodeInfo + PartialEq { /// Get this node's first child. fn first_child(&self) -> Option; - /// Get this node's first child. + /// Get this node's last child. fn last_child(&self) -> Option; /// Get this node's previous sibling. diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 3f23981a823..476e710795d 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -409,9 +409,11 @@ impl<'ln> TNode for GeckoNode<'ln> { #[inline] fn prev_sibling(&self) -> Option { unsafe { - bindings::Gecko_GetPreviousSibling(self.0) - .as_ref() - .map(GeckoNode) + let prev_or_last = GeckoNode::from_content(self.0.mPreviousOrLastSibling.as_ref()?); + if prev_or_last.0.mNextSibling.raw::().is_null() { + return None; + } + Some(prev_or_last) } }