mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
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:
parent
db53845694
commit
4878422c93
14 changed files with 176 additions and 211 deletions
|
@ -48,7 +48,7 @@ use malloc_size_of::MallocUnconditionalShallowSizeOf;
|
|||
use selectors::attr::{CaseSensitivity, NamespaceConstraint};
|
||||
use selectors::bloom::BloomFilter;
|
||||
use selectors::matching::VisitedHandlingMode;
|
||||
use selectors::matching::{matches_selector, ElementSelectorFlags, MatchingContext, MatchingMode};
|
||||
use selectors::matching::{matches_selector, MatchingContext, MatchingMode, NeedsSelectorFlags};
|
||||
use selectors::parser::{AncestorHashes, Combinator, Component, Selector, SelectorIter};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use selectors::NthIndexCache;
|
||||
|
@ -1072,22 +1072,12 @@ impl Stylist {
|
|||
{
|
||||
debug_assert!(pseudo.is_lazy());
|
||||
|
||||
// Apply the selector flags. We should be in sequential mode
|
||||
// already, so we can directly apply the parent flags.
|
||||
let mut set_selector_flags = |element: &E, flags: ElementSelectorFlags| {
|
||||
if cfg!(feature = "servo") {
|
||||
// Servo calls this function from the worker, but only for internal
|
||||
// pseudos, so we should never generate selector flags here.
|
||||
unreachable!("internal pseudo generated slow selector flags?");
|
||||
}
|
||||
|
||||
// No need to bother setting the selector flags when we're computing
|
||||
// default styles.
|
||||
if rule_inclusion == RuleInclusion::DefaultOnly {
|
||||
return;
|
||||
}
|
||||
|
||||
element.apply_selector_flags(flags);
|
||||
// No need to bother setting the selector flags when we're computing
|
||||
// default styles.
|
||||
let needs_selector_flags = if rule_inclusion == RuleInclusion::DefaultOnly {
|
||||
NeedsSelectorFlags::No
|
||||
} else {
|
||||
NeedsSelectorFlags::Yes
|
||||
};
|
||||
|
||||
let mut declarations = ApplicableDeclarationList::new();
|
||||
|
@ -1096,6 +1086,7 @@ impl Stylist {
|
|||
None,
|
||||
None,
|
||||
self.quirks_mode,
|
||||
needs_selector_flags,
|
||||
);
|
||||
|
||||
matching_context.pseudo_element_matching_fn = matching_fn;
|
||||
|
@ -1109,7 +1100,6 @@ impl Stylist {
|
|||
rule_inclusion,
|
||||
&mut declarations,
|
||||
&mut matching_context,
|
||||
&mut set_selector_flags,
|
||||
);
|
||||
|
||||
if declarations.is_empty() && is_probe {
|
||||
|
@ -1127,6 +1117,7 @@ impl Stylist {
|
|||
None,
|
||||
VisitedHandlingMode::RelevantLinkVisited,
|
||||
self.quirks_mode,
|
||||
needs_selector_flags,
|
||||
);
|
||||
matching_context.pseudo_element_matching_fn = matching_fn;
|
||||
|
||||
|
@ -1139,7 +1130,6 @@ impl Stylist {
|
|||
rule_inclusion,
|
||||
&mut declarations,
|
||||
&mut matching_context,
|
||||
&mut set_selector_flags,
|
||||
);
|
||||
if !declarations.is_empty() {
|
||||
let rule_node = self.rule_tree.insert_ordered_rules_with_important(
|
||||
|
@ -1252,7 +1242,7 @@ impl Stylist {
|
|||
}
|
||||
|
||||
/// Returns the applicable CSS declarations for the given element.
|
||||
pub fn push_applicable_declarations<E, F>(
|
||||
pub fn push_applicable_declarations<E>(
|
||||
&self,
|
||||
element: E,
|
||||
pseudo_element: Option<&PseudoElement>,
|
||||
|
@ -1262,10 +1252,8 @@ impl Stylist {
|
|||
rule_inclusion: RuleInclusion,
|
||||
applicable_declarations: &mut ApplicableDeclarationList,
|
||||
context: &mut MatchingContext<E::Impl>,
|
||||
flags_setter: &mut F,
|
||||
) where
|
||||
E: TElement,
|
||||
F: FnMut(&E, ElementSelectorFlags),
|
||||
{
|
||||
RuleCollector::new(
|
||||
self,
|
||||
|
@ -1277,7 +1265,6 @@ impl Stylist {
|
|||
rule_inclusion,
|
||||
applicable_declarations,
|
||||
context,
|
||||
flags_setter,
|
||||
)
|
||||
.collect_all();
|
||||
}
|
||||
|
@ -1357,16 +1344,15 @@ impl Stylist {
|
|||
|
||||
/// Computes the match results of a given element against the set of
|
||||
/// revalidation selectors.
|
||||
pub fn match_revalidation_selectors<E, F>(
|
||||
pub fn match_revalidation_selectors<E>(
|
||||
&self,
|
||||
element: E,
|
||||
bloom: Option<&BloomFilter>,
|
||||
nth_index_cache: &mut NthIndexCache,
|
||||
flags_setter: &mut F,
|
||||
needs_selector_flags: NeedsSelectorFlags,
|
||||
) -> SmallBitVec
|
||||
where
|
||||
E: TElement,
|
||||
F: FnMut(&E, ElementSelectorFlags),
|
||||
{
|
||||
// NB: `MatchingMode` doesn't really matter, given we don't share style
|
||||
// between pseudos.
|
||||
|
@ -1375,6 +1361,7 @@ impl Stylist {
|
|||
bloom,
|
||||
Some(nth_index_cache),
|
||||
self.quirks_mode,
|
||||
needs_selector_flags,
|
||||
);
|
||||
|
||||
// Note that, by the time we're revalidating, we're guaranteed that the
|
||||
|
@ -1397,7 +1384,6 @@ impl Stylist {
|
|||
Some(&selector_and_hashes.hashes),
|
||||
&element,
|
||||
matching_context,
|
||||
flags_setter,
|
||||
));
|
||||
true
|
||||
},
|
||||
|
@ -1420,7 +1406,6 @@ impl Stylist {
|
|||
Some(&selector_and_hashes.hashes),
|
||||
&element,
|
||||
&mut matching_context,
|
||||
flags_setter,
|
||||
));
|
||||
true
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue