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
This commit is contained in:
Emilio Cobos Álvarez 2023-05-22 10:03:20 +02:00 committed by Oriol Brufau
parent 695ff236c8
commit 1918c1c203
2 changed files with 6 additions and 4 deletions

View file

@ -151,7 +151,7 @@ pub trait TNode: Sized + Copy + Clone + Debug + NodeInfo + PartialEq {
/// Get this node's first child.
fn first_child(&self) -> Option<Self>;
/// Get this node's first child.
/// Get this node's last child.
fn last_child(&self) -> Option<Self>;
/// Get this node's previous sibling.

View file

@ -409,9 +409,11 @@ impl<'ln> TNode for GeckoNode<'ln> {
#[inline]
fn prev_sibling(&self) -> Option<Self> {
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::<nsIContent>().is_null() {
return None;
}
Some(prev_or_last)
}
}