Skip to content

Commit

Permalink
style: Manually tweak inlining in stateless pseudo selector matching.
Browse files Browse the repository at this point in the history
This addresses a minor regression in bloom-matching.html. The common
case here is that there's no selector to the right of the
pseudo-element, so keep that path inline, while keeping all other checks
out of line.

Differential Revision: https://phabricator.services.mozilla.com/D76793
  • Loading branch information
emilio committed Jun 3, 2020
1 parent a9c8872 commit 4cf9aee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
9 changes: 2 additions & 7 deletions components/selectors/matching.rs
Expand Up @@ -322,13 +322,8 @@ where
},
}

for component in &mut iter {
// The only other parser-allowed Components in this sequence are
// state pseudo-classes, or one of the other things that can contain
// them.
if !component.matches_for_stateless_pseudo_element() {
return false;
}
if !iter.matches_for_stateless_pseudo_element() {
return false;
}

// Advance to the non-pseudo-element part of the selector.
Expand Down
29 changes: 28 additions & 1 deletion components/selectors/parser.rs
Expand Up @@ -802,6 +802,33 @@ impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> {
self.next_sequence().is_none()
}

#[inline]
pub(crate) fn matches_for_stateless_pseudo_element(&mut self) -> bool {
let first = match self.next() {
Some(c) => c,
// Note that this is the common path that we keep inline: the
// pseudo-element not having anything to its right.
None => return true,
};
self.matches_for_stateless_pseudo_element_internal(first)
}

#[inline(never)]
fn matches_for_stateless_pseudo_element_internal(&mut self, first: &Component<Impl>) -> bool {
if !first.matches_for_stateless_pseudo_element() {
return false;
}
for component in self {
// The only other parser-allowed Components in this sequence are
// state pseudo-classes, or one of the other things that can contain
// them.
if !component.matches_for_stateless_pseudo_element() {
return false;
}
}
true
}

/// Returns remaining count of the simple selectors and combinators in the Selector.
#[inline]
pub fn selector_length(&self) -> usize {
Expand Down Expand Up @@ -1076,7 +1103,7 @@ impl<Impl: SelectorImpl> Component<Impl> {
/// `maybe_allowed_after_pseudo_element` should end up here, and
/// `NonTSPseudoClass` never matches (as it is a stateless pseudo after
/// all).
pub(crate) fn matches_for_stateless_pseudo_element(&self) -> bool {
fn matches_for_stateless_pseudo_element(&self) -> bool {
debug_assert!(
self.maybe_allowed_after_pseudo_element(),
"Someone messed up pseudo-element parsing: {:?}",
Expand Down

0 comments on commit 4cf9aee

Please sign in to comment.