From 5ccce5911ff2bedd54e9cfd45ebda02a1bcdf857 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 18 Sep 2016 19:56:14 -0400 Subject: [PATCH] Flush style sharing cache on parent mismatch. --- components/style/matching.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/style/matching.rs b/components/style/matching.rs index 4edf85d1d3cc..5a37d0eb3285 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -708,6 +708,7 @@ pub trait ElementMatchMethods : TElement { _ => return StyleSharingResult::CannotShare, }; + let mut should_clear_cache = false; for (i, &mut (ref mut candidate, ())) in style_sharing_candidate_cache.iter_mut().enumerate() { let sharing_result = self.share_style_with_candidate_if_possible(parent, shared_context, @@ -750,6 +751,11 @@ pub trait ElementMatchMethods : TElement { // Cache miss, let's see what kind of failure to decide // whether we keep trying or not. match miss { + // Cache miss because of parent, clear the candidate cache. + CacheMiss::Parent => { + should_clear_cache = true; + break; + }, // Too expensive failure, give up, we don't want another // one of these. CacheMiss::CommonStyleAffectingAttributes | @@ -761,6 +767,9 @@ pub trait ElementMatchMethods : TElement { } } } + if should_clear_cache { + style_sharing_candidate_cache.clear(); + } StyleSharingResult::CannotShare }