style: Simplify selector flags setup even more

In my investigation for bug 1766439, I am digging into why selector
matching regressed.

It doesn't help that the selector-matching code is instantiated a
gazillion times (so there's a ton of copies of the relevant functions).

This was needed in the past because we had different ways of setting the
selector flags on elements, but I unified that recently and now we only
need to either set them or not. That is the kind of thing that
MatchingContext is really good for, so pass that instead on
MatchingContext creation.

Differential Revision: https://phabricator.services.mozilla.com/D145428
This commit is contained in:
Emilio Cobos Álvarez 2023-08-12 00:26:15 +02:00 committed by Martin Robinson
parent db53845694
commit 4878422c93
14 changed files with 176 additions and 211 deletions

View file

@ -19,8 +19,7 @@ use crate::selector_parser::Snapshot;
use crate::stylesheets::origin::OriginSet;
use crate::{Atom, WeakAtom};
use selectors::attr::CaseSensitivity;
use selectors::matching::matches_selector;
use selectors::matching::{MatchingContext, MatchingMode, VisitedHandlingMode};
use selectors::matching::{matches_selector, MatchingContext, MatchingMode, VisitedHandlingMode, NeedsSelectorFlags};
use selectors::NthIndexCache;
use smallvec::SmallVec;
@ -67,6 +66,7 @@ impl<'a, 'b: 'a, E: TElement + 'b> StateAndAttrInvalidationProcessor<'a, 'b, E>
Some(nth_index_cache),
VisitedHandlingMode::AllLinksVisitedAndUnvisited,
shared_context.quirks_mode(),
NeedsSelectorFlags::No,
);
Self {
@ -84,7 +84,7 @@ pub fn check_dependency<E, W>(
dependency: &Dependency,
element: &E,
wrapper: &W,
mut context: &mut MatchingContext<'_, E::Impl>,
context: &mut MatchingContext<'_, E::Impl>,
) -> bool
where
E: TElement,
@ -95,8 +95,7 @@ where
dependency.selector_offset,
None,
element,
&mut context,
&mut |_, _| {},
context,
);
let matched_then = matches_selector(
@ -104,8 +103,7 @@ where
dependency.selector_offset,
None,
wrapper,
&mut context,
&mut |_, _| {},
context,
);
matched_then != matches_now