diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index ec818add99c..a9ea5f615b8 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -82,6 +82,7 @@ use smallvec::SmallVec; use std::marker::PhantomData; use std::mem; use std::ops::Deref; +use style_resolver::PrimaryStyle; use stylist::Stylist; mod checks; @@ -546,11 +547,18 @@ impl StyleSharingCache { /// /// NB: We pass a source for the validation data, rather than the data itself, /// to avoid memmoving at each function call. See rust issue #42763. - pub fn insert_if_possible(&mut self, - element: &E, - style: &ComputedValues, - validation_data_holder: Option<&mut StyleSharingTarget>, - dom_depth: usize) { + pub fn insert_if_possible( + &mut self, + element: &E, + style: &PrimaryStyle, + validation_data_holder: Option<&mut StyleSharingTarget>, + dom_depth: usize, + ) { + if style.0.reused_via_rule_node { + debug!("Failing to insert into the cached: this was a cached style"); + return; + } + let parent = match element.traversal_parent() { Some(element) => element, None => { @@ -583,7 +591,7 @@ impl StyleSharingCache { // // These are things we don't check in the candidate match because they // are either uncommon or expensive. - let box_style = style.get_box(); + let box_style = style.style().get_box(); if box_style.specifies_transitions() { debug!("Failing to insert to the cache: transitions"); return; diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 2823abddec8..20386d754b4 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -678,14 +678,12 @@ where resolver.resolve_style_with_default_parents() }; - context.thread_local - .sharing_cache - .insert_if_possible( - &element, - new_styles.primary.style(), - Some(&mut target), - traversal_data.current_dom_depth, - ); + context.thread_local.sharing_cache.insert_if_possible( + &element, + &new_styles.primary, + Some(&mut target), + traversal_data.current_dom_depth, + ); new_styles } @@ -724,9 +722,10 @@ where resolver.cascade_styles_with_default_parents(cascade_inputs) }; + context.thread_local.sharing_cache.insert_if_possible( &element, - new_styles.primary.style(), + &new_styles.primary, None, traversal_data.current_dom_depth, );