mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Bug 1360399: Don't deduplicate revalidation selectors. r=bholley
It's unfortunate, but it's a correctness issue. I was looking at the expectations update here: * https://hg.mozilla.org/integration/autoland/rev/659cddddd434 And investigating it I realised that it's wrong to coalesce selectors like that, because we keep the bloom filter flags. So in the test cases disabled, we have a selector that looks like this: msub > :not(:first-child), msup > :not(:first-child), msubsup > :not(:first-child), mmultiscripts > :not(:first-child) { -moz-script-level: +1; -moz-math-display: inline; } And an element that looks like this: <msubsup><mi></mi><mi></mi></msubsup> We're only inserting the first selector msub > :not(:first-child) into the set, so when we're going to match the <mi> elements we fast-reject it in both cases due to the bloom filter, so they share style. I can't see an easy way to fix this keeping the deduplication. If we keep it, we need to remove the bloom filter optimization, which means that we'd trash the cache for every first-child in the document (the :not(:first-child) effectively becomes a global rule). MozReview-Commit-ID: 9VPkmdj9zDg Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
04aac0247a
commit
7a556a7f03
3 changed files with 17 additions and 23 deletions
|
@ -476,12 +476,12 @@ pub enum Component<Impl: SelectorImpl> {
|
||||||
//
|
//
|
||||||
// CSS3 Negation only takes a simple simple selector, but we still need to
|
// CSS3 Negation only takes a simple simple selector, but we still need to
|
||||||
// treat it as a compound selector because it might be a type selector which
|
// treat it as a compound selector because it might be a type selector which
|
||||||
// we represent as a namespace and and localname.
|
// we represent as a namespace and a localname.
|
||||||
//
|
//
|
||||||
// Note: if/when we upgrade this to CSS4, which supports combinators, we need
|
// Note: if/when we upgrade this to CSS4, which supports combinators, we
|
||||||
// to think about how this should interact with visit_complex_selector, and
|
// need to think about how this should interact with visit_complex_selector,
|
||||||
// what the consumers of those APIs should do about the presence of combinators
|
// and what the consumers of those APIs should do about the presence of
|
||||||
// in negation.
|
// combinators in negation.
|
||||||
Negation(Box<[Component<Impl>]>),
|
Negation(Box<[Component<Impl>]>),
|
||||||
FirstChild, LastChild, OnlyChild,
|
FirstChild, LastChild, OnlyChild,
|
||||||
Root,
|
Root,
|
||||||
|
|
|
@ -199,6 +199,8 @@ fn element_matches_candidate<E: TElement>(element: &E,
|
||||||
debug_assert!(data.has_current_styles());
|
debug_assert!(data.has_current_styles());
|
||||||
let current_styles = data.styles();
|
let current_styles = data.styles();
|
||||||
|
|
||||||
|
debug!("Sharing style between {:?} and {:?}", element, candidate_element);
|
||||||
|
|
||||||
Ok(current_styles.primary.clone())
|
Ok(current_styles.primary.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -336,20 +336,12 @@ impl Stylist {
|
||||||
self.dependencies.note_selector(selector);
|
self.dependencies.note_selector(selector);
|
||||||
|
|
||||||
if needs_revalidation(selector) {
|
if needs_revalidation(selector) {
|
||||||
// For revalidation, we can skip everything left of the first ancestor
|
// For revalidation, we can skip everything left of
|
||||||
// combinator.
|
// the first ancestor combinator.
|
||||||
let revalidation_sel = selector.inner.slice_to_first_ancestor_combinator();
|
let revalidation_sel =
|
||||||
|
selector.inner.slice_to_first_ancestor_combinator();
|
||||||
|
|
||||||
// Because of the slicing we do above, we can often end up with
|
self.selectors_for_cache_revalidation.push(revalidation_sel);
|
||||||
// adjacent duplicate selectors when we have selectors like
|
|
||||||
// body > foo, td > foo, th > foo, etc. Doing a check for
|
|
||||||
// adjacent duplicates here reduces the number of revalidation
|
|
||||||
// selectors for Gecko's UA sheet by 30%.
|
|
||||||
let duplicate = self.selectors_for_cache_revalidation.last()
|
|
||||||
.map_or(false, |x| x.complex == revalidation_sel.complex);
|
|
||||||
if !duplicate {
|
|
||||||
self.selectors_for_cache_revalidation.push(revalidation_sel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -844,7 +836,7 @@ impl Stylist {
|
||||||
flags_setter: &mut F)
|
flags_setter: &mut F)
|
||||||
-> BitVec
|
-> BitVec
|
||||||
where E: TElement,
|
where E: TElement,
|
||||||
F: FnMut(&E, ElementSelectorFlags)
|
F: FnMut(&E, ElementSelectorFlags),
|
||||||
{
|
{
|
||||||
use selectors::matching::StyleRelations;
|
use selectors::matching::StyleRelations;
|
||||||
use selectors::matching::matches_selector;
|
use selectors::matching::matches_selector;
|
||||||
|
@ -957,8 +949,8 @@ impl SelectorVisitor for RevalidationVisitor {
|
||||||
Component::OnlyOfType => {
|
Component::OnlyOfType => {
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
Component::NonTSPseudoClass(ref p) if p.needs_cache_revalidation() => {
|
Component::NonTSPseudoClass(ref p) => {
|
||||||
false
|
!p.needs_cache_revalidation()
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
true
|
true
|
||||||
|
@ -984,8 +976,8 @@ pub fn needs_revalidation(selector: &Selector<SelectorImpl>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If none of the simple selectors in the rightmost sequence required
|
// If none of the simple selectors in the rightmost sequence required
|
||||||
// revalidaiton, we need revalidation if and only if the combinator is
|
// revalidation, we need revalidation if and only if the combinator is a
|
||||||
// a sibling combinator.
|
// sibling combinator.
|
||||||
iter.next_sequence().map_or(false, |c| c.is_sibling())
|
iter.next_sequence().map_or(false, |c| c.is_sibling())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue