diff --git a/components/style/context.rs b/components/style/context.rs index ef19d45b6d9..cbcac7e9982 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -463,7 +463,7 @@ impl ThreadLocalStyleContext { self.current_element_info = Some(CurrentElementInfo { element: element.as_node().opaque(), is_initial_style: !data.has_styles(), - validation_data: ValidationData::new(), + validation_data: ValidationData::default(), possibly_expired_animations: Vec::new(), }); } diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index 2cdd0913ae6..0975e0cf4e1 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -16,6 +16,7 @@ use properties::ComputedValues; use selectors::bloom::BloomFilter; use selectors::matching::{ElementSelectorFlags, StyleRelations}; use smallvec::SmallVec; +use std::mem; use std::ops::Deref; use stylist::{ApplicableDeclarationBlock, Stylist}; @@ -36,7 +37,7 @@ pub enum StyleSharingBehavior { /// Some data we want to avoid recomputing all the time while trying to share /// style. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct ValidationData { /// The class list of this element. /// @@ -53,23 +54,9 @@ pub struct ValidationData { } impl ValidationData { - /// Trivially construct an empty `ValidationData` with nothing on - /// it. - pub fn new() -> Self { - Self { - class_list: None, - pres_hints: None, - revalidation_match_results: None, - } - } - /// Move the cached data to a new instance, and return it. pub fn take(&mut self) -> Self { - Self { - class_list: self.class_list.take(), - pres_hints: self.pres_hints.take(), - revalidation_match_results: self.revalidation_match_results.take(), - } + mem::replace(self, Self::default()) } /// Get or compute the list of presentational attributes associated with @@ -189,7 +176,7 @@ impl StyleSharingTarget { pub fn new(element: E) -> Self { Self { element: element, - validation_data: ValidationData::new(), + validation_data: ValidationData::default(), } } @@ -242,8 +229,6 @@ impl StyleSharingTarget { data: &mut ElementData) -> StyleSharingResult { - use std::mem; - let shared_context = &context.shared; let selector_flags_map = &mut context.thread_local.selector_flags; let bloom_filter = context.thread_local.bloom_filter.filter(); @@ -256,12 +241,9 @@ impl StyleSharingTarget { &mut self, data); - mem::swap(&mut self.validation_data, - &mut context - .thread_local - .current_element_info.as_mut().unwrap() - .validation_data); + context.thread_local.current_element_info.as_mut().unwrap().validation_data = + self.validation_data.take(); result } }