diff --git a/components/style/matching.rs b/components/style/matching.rs index 20344b86f21..e1c1ba47223 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -102,6 +102,17 @@ pub enum CacheMiss { Revalidation, } +fn same_computed_values(first: Option, second: Option) -> bool { + let (a, b) = match (first, second) { + (Some(f), Some(s)) => (f, s), + _ => return false, + }; + + let eq = ::arc_ptr_eq(a.borrow_data().unwrap().styles().primary.values(), + b.borrow_data().unwrap().styles().primary.values()); + eq +} + fn element_matches_candidate(element: &E, candidate: &mut StyleSharingCandidate, candidate_element: &E, @@ -116,7 +127,12 @@ fn element_matches_candidate(element: &E, } } - if element.parent_element() != candidate_element.parent_element() { + // Check that we have the same parent, or at least the same pointer identity + // for parent computed style. The latter check allows us to share style + // between cousins if the parents shared style. + let parent = element.parent_element(); + let candidate_parent = candidate_element.parent_element(); + if parent != candidate_parent && !same_computed_values(parent, candidate_parent) { miss!(Parent) }