diff --git a/components/style/context.rs b/components/style/context.rs index f36df67a55c..103c3a5a7d3 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -21,7 +21,7 @@ use rule_tree::StrongRuleNode; use selector_parser::{EAGER_PSEUDO_COUNT, SnapshotMap}; use selectors::matching::ElementSelectorFlags; use shared_lock::StylesheetGuards; -use sharing::{ValidationData, StyleSharingCandidateCache}; +use sharing::StyleSharingCandidateCache; use std::fmt; use std::ops::Add; #[cfg(feature = "servo")] use std::sync::Mutex; @@ -269,8 +269,6 @@ pub struct CurrentElementInfo { element: OpaqueNode, /// Whether the element is being styled for the first time. is_initial_style: bool, - /// Lazy cache of the different data used for style sharing. - pub validation_data: ValidationData, /// A Vec of possibly expired animations. Used only by Servo. #[allow(dead_code)] pub possibly_expired_animations: Vec, @@ -575,7 +573,6 @@ impl ThreadLocalStyleContext { self.current_element_info = Some(CurrentElementInfo { element: element.as_node().opaque(), is_initial_style: !data.has_styles(), - validation_data: ValidationData::default(), possibly_expired_animations: Vec::new(), }); } diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index c98e92a0dc0..2d589baa78b 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -328,7 +328,7 @@ impl StyleSharingTarget { /// Attempts to share a style with another node. pub fn share_style_if_possible( - mut self, + &mut self, context: &mut StyleContext, ) -> StyleSharingResult { let cache = &mut context.thread_local.style_sharing_candidate_cache; @@ -344,17 +344,17 @@ impl StyleSharingTarget { debug_assert_eq!(bloom_filter.current_parent(), self.element.traversal_parent()); - let result = - cache.share_style_if_possible( - shared_context, - selector_flags_map, - bloom_filter, - &mut self - ); + cache.share_style_if_possible( + shared_context, + selector_flags_map, + bloom_filter, + self + ) + } - context.thread_local.current_element_info.as_mut().unwrap().validation_data = - self.validation_data.take(); - result + /// Gets the validation data used to match against this target, if any. + pub fn take_validation_data(&mut self) -> ValidationData { + self.validation_data.take() } } diff --git a/components/style/traversal.rs b/components/style/traversal.rs index f7738f70eab..afe0aa31f7d 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -777,7 +777,7 @@ where // This is only relevant for animations as of right now. important_rules_changed = true; - let target = StyleSharingTarget::new(element); + let mut target = StyleSharingTarget::new(element); match target.share_style_if_possible(context) { StyleWasShared(index, styles) => { context.thread_local.statistics.styles_shared += 1; @@ -791,29 +791,13 @@ where StyleResolverForElement::new(element, context, RuleInclusion::All) .resolve_style_with_default_parents(); - // If we previously tried to match this element against the - // cache, the revalidation match results will already be - // cached. Otherwise we'll have None, and compute them later - // on-demand. - // - // If we do have the results, grab them here to satisfy the - // borrow checker. - let validation_data = - context.thread_local - .current_element_info - .as_mut().unwrap() - .validation_data - .take(); - - let dom_depth = - context.thread_local.bloom_filter.matching_depth(); context.thread_local .style_sharing_candidate_cache .insert_if_possible( &element, new_styles.primary(), - validation_data, - dom_depth + target.take_validation_data(), + context.thread_local.bloom_filter.matching_depth(), ); new_styles