From 25832b962f4b969e88b441ed4a1cf5fdbb579ada Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 26 Apr 2017 17:25:43 -0700 Subject: [PATCH] Check for adjacent duplicates when accumulating revalidation selectors. MozReview-Commit-ID: 4C8L5u1S1sL --- components/style/stylist.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 78a77266800..62f1795f25c 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -336,7 +336,20 @@ impl Stylist { self.dependencies.note_selector(selector); if needs_revalidation(selector) { - self.selectors_for_cache_revalidation.push(selector.inner.slice_to_first_ancestor_combinator()); + // For revalidation, we can skip everything left of the 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 + // 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); + } } } }