Reduce the number of places where we need to enumerate ValidationData members.

MozReview-Commit-ID: 9m2ebknBFSE
This commit is contained in:
Bobby Holley 2017-05-30 16:47:28 -07:00
parent 6d8455a916
commit f40c45fe1a
2 changed files with 7 additions and 25 deletions

View file

@ -463,7 +463,7 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
self.current_element_info = Some(CurrentElementInfo { self.current_element_info = Some(CurrentElementInfo {
element: element.as_node().opaque(), element: element.as_node().opaque(),
is_initial_style: !data.has_styles(), is_initial_style: !data.has_styles(),
validation_data: ValidationData::new(), validation_data: ValidationData::default(),
possibly_expired_animations: Vec::new(), possibly_expired_animations: Vec::new(),
}); });
} }

View file

@ -16,6 +16,7 @@ use properties::ComputedValues;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{ElementSelectorFlags, StyleRelations}; use selectors::matching::{ElementSelectorFlags, StyleRelations};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::mem;
use std::ops::Deref; use std::ops::Deref;
use stylist::{ApplicableDeclarationBlock, Stylist}; 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 /// Some data we want to avoid recomputing all the time while trying to share
/// style. /// style.
#[derive(Debug)] #[derive(Debug, Default)]
pub struct ValidationData { pub struct ValidationData {
/// The class list of this element. /// The class list of this element.
/// ///
@ -53,23 +54,9 @@ pub struct ValidationData {
} }
impl 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. /// Move the cached data to a new instance, and return it.
pub fn take(&mut self) -> Self { pub fn take(&mut self) -> Self {
Self { mem::replace(self, Self::default())
class_list: self.class_list.take(),
pres_hints: self.pres_hints.take(),
revalidation_match_results: self.revalidation_match_results.take(),
}
} }
/// Get or compute the list of presentational attributes associated with /// Get or compute the list of presentational attributes associated with
@ -189,7 +176,7 @@ impl<E: TElement> StyleSharingTarget<E> {
pub fn new(element: E) -> Self { pub fn new(element: E) -> Self {
Self { Self {
element: element, element: element,
validation_data: ValidationData::new(), validation_data: ValidationData::default(),
} }
} }
@ -242,8 +229,6 @@ impl<E: TElement> StyleSharingTarget<E> {
data: &mut ElementData) data: &mut ElementData)
-> StyleSharingResult -> StyleSharingResult
{ {
use std::mem;
let shared_context = &context.shared; let shared_context = &context.shared;
let selector_flags_map = &mut context.thread_local.selector_flags; let selector_flags_map = &mut context.thread_local.selector_flags;
let bloom_filter = context.thread_local.bloom_filter.filter(); let bloom_filter = context.thread_local.bloom_filter.filter();
@ -256,12 +241,9 @@ impl<E: TElement> StyleSharingTarget<E> {
&mut self, &mut self,
data); 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 result
} }
} }