s/CachedStyleSharingData/ValidationData.

I still think CachedStyleSharingData should be the name, but not going to fight
over it.
This commit is contained in:
Emilio Cobos Álvarez 2017-05-30 11:23:59 +02:00
parent 0adc02a317
commit 7db2776348
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 37 additions and 34 deletions

View file

@ -21,7 +21,7 @@ use font_metrics::FontMetricsProvider;
use selector_parser::SnapshotMap; use selector_parser::SnapshotMap;
use selectors::matching::ElementSelectorFlags; use selectors::matching::ElementSelectorFlags;
use shared_lock::StylesheetGuards; use shared_lock::StylesheetGuards;
use sharing::{CachedStyleSharingData, StyleSharingCandidateCache}; use sharing::{ValidationData, StyleSharingCandidateCache};
use std::fmt; use std::fmt;
use std::ops::Add; use std::ops::Add;
#[cfg(feature = "servo")] use std::sync::Mutex; #[cfg(feature = "servo")] use std::sync::Mutex;
@ -165,7 +165,7 @@ pub struct CurrentElementInfo {
/// Whether the element is being styled for the first time. /// Whether the element is being styled for the first time.
is_initial_style: bool, is_initial_style: bool,
/// Lazy cache of the different data used for style sharing. /// Lazy cache of the different data used for style sharing.
pub cached_style_sharing_data: CachedStyleSharingData, pub validation_data: ValidationData,
/// A Vec of possibly expired animations. Used only by Servo. /// A Vec of possibly expired animations. Used only by Servo.
#[allow(dead_code)] #[allow(dead_code)]
pub possibly_expired_animations: Vec<PropertyAnimation>, pub possibly_expired_animations: Vec<PropertyAnimation>,
@ -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(),
cached_style_sharing_data: CachedStyleSharingData::new(), validation_data: ValidationData::new(),
possibly_expired_animations: Vec::new(), possibly_expired_animations: Vec::new(),
}); });
} }

View file

@ -855,17 +855,19 @@ pub trait MatchMethods : TElement {
// //
// If we do have the results, grab them here to satisfy the borrow // If we do have the results, grab them here to satisfy the borrow
// checker. // checker.
let revalidation_match_results = context.thread_local let validation_data =
.current_element_info context.thread_local
.as_mut().unwrap() .current_element_info
.cached_style_sharing_data .as_mut().unwrap()
.take(); .validation_data
.take();
context.thread_local context.thread_local
.style_sharing_candidate_cache .style_sharing_candidate_cache
.insert_if_possible(self, .insert_if_possible(self,
data.styles().primary.values(), data.styles().primary.values(),
primary_results.relations, primary_results.relations,
revalidation_match_results); validation_data);
} }
child_cascade_requirement child_cascade_requirement

View file

@ -37,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)]
pub struct CachedStyleSharingData { pub struct ValidationData {
/// The class list of this element. /// The class list of this element.
/// ///
/// TODO(emilio): See if it's worth to sort them, or doing something else in /// TODO(emilio): See if it's worth to sort them, or doing something else in
@ -52,8 +52,8 @@ pub struct CachedStyleSharingData {
revalidation_match_results: Option<BitVec>, revalidation_match_results: Option<BitVec>,
} }
impl CachedStyleSharingData { impl ValidationData {
/// Trivially construct an empty `CachedStyleSharingData` with nothing on /// Trivially construct an empty `ValidationData` with nothing on
/// it. /// it.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -129,18 +129,18 @@ pub struct StyleSharingCandidate<E: TElement> {
/// The element. We use SendElement here so that the cache may live in /// The element. We use SendElement here so that the cache may live in
/// ScopedTLS. /// ScopedTLS.
element: SendElement<E>, element: SendElement<E>,
cache: CachedStyleSharingData, validation_data: ValidationData,
} }
impl<E: TElement> StyleSharingCandidate<E> { impl<E: TElement> StyleSharingCandidate<E> {
/// Get the classlist of this candidate. /// Get the classlist of this candidate.
fn class_list(&mut self) -> &[Atom] { fn class_list(&mut self) -> &[Atom] {
self.cache.class_list(*self.element) self.validation_data.class_list(*self.element)
} }
/// Get the pres hints of this candidate. /// Get the pres hints of this candidate.
fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] { fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] {
self.cache.pres_hints(*self.element) self.validation_data.pres_hints(*self.element)
} }
/// Get the classlist of this candidate. /// Get the classlist of this candidate.
@ -149,10 +149,11 @@ impl<E: TElement> StyleSharingCandidate<E> {
stylist: &Stylist, stylist: &Stylist,
bloom: &BloomFilter, bloom: &BloomFilter,
) -> &BitVec { ) -> &BitVec {
self.cache.revalidation_match_results(*self.element, self.validation_data.revalidation_match_results(
stylist, *self.element,
bloom, stylist,
&mut |_, _| {}) bloom,
&mut |_, _| {})
} }
} }
@ -165,7 +166,7 @@ impl<E: TElement> PartialEq<StyleSharingCandidate<E>> for StyleSharingCandidate<
/// An element we want to test against the style sharing cache. /// An element we want to test against the style sharing cache.
pub struct StyleSharingTarget<E: TElement> { pub struct StyleSharingTarget<E: TElement> {
element: E, element: E,
cache: CachedStyleSharingData, validation_data: ValidationData,
} }
impl<E: TElement> Deref for StyleSharingTarget<E> { impl<E: TElement> Deref for StyleSharingTarget<E> {
@ -181,17 +182,17 @@ impl<E: TElement> StyleSharingTarget<E> {
pub fn new(element: E) -> Self { pub fn new(element: E) -> Self {
Self { Self {
element: element, element: element,
cache: CachedStyleSharingData::new(), validation_data: ValidationData::new(),
} }
} }
fn class_list(&mut self) -> &[Atom] { fn class_list(&mut self) -> &[Atom] {
self.cache.class_list(self.element) self.validation_data.class_list(self.element)
} }
/// Get the pres hints of this candidate. /// Get the pres hints of this candidate.
fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] { fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] {
self.cache.pres_hints(self.element) self.validation_data.pres_hints(self.element)
} }
fn revalidation_match_results( fn revalidation_match_results(
@ -220,10 +221,11 @@ impl<E: TElement> StyleSharingTarget<E> {
element.apply_selector_flags(selector_flags_map, el, flags); element.apply_selector_flags(selector_flags_map, el, flags);
}; };
self.cache.revalidation_match_results(self.element, self.validation_data.revalidation_match_results(
stylist, self.element,
bloom, stylist,
&mut set_selector_flags) bloom,
&mut set_selector_flags)
} }
/// Attempts to share a style with another node. /// Attempts to share a style with another node.
@ -247,12 +249,11 @@ impl<E: TElement> StyleSharingTarget<E> {
&mut self, &mut self,
data); data);
// FIXME(emilio): Do this in a cleaner way. mem::swap(&mut self.validation_data,
mem::swap(&mut self.cache,
&mut context &mut context
.thread_local .thread_local
.current_element_info.as_mut().unwrap() .current_element_info.as_mut().unwrap()
.cached_style_sharing_data); .validation_data);
result result
} }
@ -334,7 +335,7 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
element: &E, element: &E,
style: &ComputedValues, style: &ComputedValues,
relations: StyleRelations, relations: StyleRelations,
mut cache: CachedStyleSharingData) { mut validation_data: ValidationData) {
use selectors::matching::AFFECTED_BY_PRESENTATIONAL_HINTS; use selectors::matching::AFFECTED_BY_PRESENTATIONAL_HINTS;
let parent = match element.parent_element() { let parent = match element.parent_element() {
@ -371,15 +372,15 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
// Take advantage of the information we've learned during // Take advantage of the information we've learned during
// selector-matching. // selector-matching.
if !relations.intersects(AFFECTED_BY_PRESENTATIONAL_HINTS) { if !relations.intersects(AFFECTED_BY_PRESENTATIONAL_HINTS) {
debug_assert!(cache.pres_hints.as_ref().map_or(true, |v| v.is_empty())); debug_assert!(validation_data.pres_hints.as_ref().map_or(true, |v| v.is_empty()));
cache.pres_hints = Some(SmallVec::new()); validation_data.pres_hints = Some(SmallVec::new());
} }
debug!("Inserting into cache: {:?} with parent {:?}", element, parent); debug!("Inserting into cache: {:?} with parent {:?}", element, parent);
self.cache.insert(StyleSharingCandidate { self.cache.insert(StyleSharingCandidate {
element: unsafe { SendElement::new(*element) }, element: unsafe { SendElement::new(*element) },
cache: cache, validation_data: validation_data,
}); });
} }