mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
s/CachedStyleSharingData/ValidationData.
I still think CachedStyleSharingData should be the name, but not going to fight over it.
This commit is contained in:
parent
0adc02a317
commit
7db2776348
3 changed files with 37 additions and 34 deletions
|
@ -21,7 +21,7 @@ use font_metrics::FontMetricsProvider;
|
|||
use selector_parser::SnapshotMap;
|
||||
use selectors::matching::ElementSelectorFlags;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use sharing::{CachedStyleSharingData, StyleSharingCandidateCache};
|
||||
use sharing::{ValidationData, StyleSharingCandidateCache};
|
||||
use std::fmt;
|
||||
use std::ops::Add;
|
||||
#[cfg(feature = "servo")] use std::sync::Mutex;
|
||||
|
@ -165,7 +165,7 @@ pub struct CurrentElementInfo {
|
|||
/// 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 cached_style_sharing_data: CachedStyleSharingData,
|
||||
pub validation_data: ValidationData,
|
||||
/// A Vec of possibly expired animations. Used only by Servo.
|
||||
#[allow(dead_code)]
|
||||
pub possibly_expired_animations: Vec<PropertyAnimation>,
|
||||
|
@ -463,7 +463,7 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
|||
self.current_element_info = Some(CurrentElementInfo {
|
||||
element: element.as_node().opaque(),
|
||||
is_initial_style: !data.has_styles(),
|
||||
cached_style_sharing_data: CachedStyleSharingData::new(),
|
||||
validation_data: ValidationData::new(),
|
||||
possibly_expired_animations: Vec::new(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -855,17 +855,19 @@ pub trait MatchMethods : TElement {
|
|||
//
|
||||
// If we do have the results, grab them here to satisfy the borrow
|
||||
// checker.
|
||||
let revalidation_match_results = context.thread_local
|
||||
.current_element_info
|
||||
.as_mut().unwrap()
|
||||
.cached_style_sharing_data
|
||||
.take();
|
||||
let validation_data =
|
||||
context.thread_local
|
||||
.current_element_info
|
||||
.as_mut().unwrap()
|
||||
.validation_data
|
||||
.take();
|
||||
|
||||
context.thread_local
|
||||
.style_sharing_candidate_cache
|
||||
.insert_if_possible(self,
|
||||
data.styles().primary.values(),
|
||||
primary_results.relations,
|
||||
revalidation_match_results);
|
||||
validation_data);
|
||||
}
|
||||
|
||||
child_cascade_requirement
|
||||
|
|
|
@ -37,7 +37,7 @@ pub enum StyleSharingBehavior {
|
|||
/// Some data we want to avoid recomputing all the time while trying to share
|
||||
/// style.
|
||||
#[derive(Debug)]
|
||||
pub struct CachedStyleSharingData {
|
||||
pub struct ValidationData {
|
||||
/// The class list of this element.
|
||||
///
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
impl CachedStyleSharingData {
|
||||
/// Trivially construct an empty `CachedStyleSharingData` with nothing on
|
||||
impl ValidationData {
|
||||
/// Trivially construct an empty `ValidationData` with nothing on
|
||||
/// it.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -129,18 +129,18 @@ pub struct StyleSharingCandidate<E: TElement> {
|
|||
/// The element. We use SendElement here so that the cache may live in
|
||||
/// ScopedTLS.
|
||||
element: SendElement<E>,
|
||||
cache: CachedStyleSharingData,
|
||||
validation_data: ValidationData,
|
||||
}
|
||||
|
||||
impl<E: TElement> StyleSharingCandidate<E> {
|
||||
/// Get the classlist of this candidate.
|
||||
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.
|
||||
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.
|
||||
|
@ -149,10 +149,11 @@ impl<E: TElement> StyleSharingCandidate<E> {
|
|||
stylist: &Stylist,
|
||||
bloom: &BloomFilter,
|
||||
) -> &BitVec {
|
||||
self.cache.revalidation_match_results(*self.element,
|
||||
stylist,
|
||||
bloom,
|
||||
&mut |_, _| {})
|
||||
self.validation_data.revalidation_match_results(
|
||||
*self.element,
|
||||
stylist,
|
||||
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.
|
||||
pub struct StyleSharingTarget<E: TElement> {
|
||||
element: E,
|
||||
cache: CachedStyleSharingData,
|
||||
validation_data: ValidationData,
|
||||
}
|
||||
|
||||
impl<E: TElement> Deref for StyleSharingTarget<E> {
|
||||
|
@ -181,17 +182,17 @@ impl<E: TElement> StyleSharingTarget<E> {
|
|||
pub fn new(element: E) -> Self {
|
||||
Self {
|
||||
element: element,
|
||||
cache: CachedStyleSharingData::new(),
|
||||
validation_data: ValidationData::new(),
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] {
|
||||
self.cache.pres_hints(self.element)
|
||||
self.validation_data.pres_hints(self.element)
|
||||
}
|
||||
|
||||
fn revalidation_match_results(
|
||||
|
@ -220,10 +221,11 @@ impl<E: TElement> StyleSharingTarget<E> {
|
|||
element.apply_selector_flags(selector_flags_map, el, flags);
|
||||
};
|
||||
|
||||
self.cache.revalidation_match_results(self.element,
|
||||
stylist,
|
||||
bloom,
|
||||
&mut set_selector_flags)
|
||||
self.validation_data.revalidation_match_results(
|
||||
self.element,
|
||||
stylist,
|
||||
bloom,
|
||||
&mut set_selector_flags)
|
||||
}
|
||||
|
||||
/// Attempts to share a style with another node.
|
||||
|
@ -247,12 +249,11 @@ impl<E: TElement> StyleSharingTarget<E> {
|
|||
&mut self,
|
||||
data);
|
||||
|
||||
// FIXME(emilio): Do this in a cleaner way.
|
||||
mem::swap(&mut self.cache,
|
||||
mem::swap(&mut self.validation_data,
|
||||
&mut context
|
||||
.thread_local
|
||||
.current_element_info.as_mut().unwrap()
|
||||
.cached_style_sharing_data);
|
||||
.validation_data);
|
||||
|
||||
result
|
||||
}
|
||||
|
@ -334,7 +335,7 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
|||
element: &E,
|
||||
style: &ComputedValues,
|
||||
relations: StyleRelations,
|
||||
mut cache: CachedStyleSharingData) {
|
||||
mut validation_data: ValidationData) {
|
||||
use selectors::matching::AFFECTED_BY_PRESENTATIONAL_HINTS;
|
||||
|
||||
let parent = match element.parent_element() {
|
||||
|
@ -371,15 +372,15 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
|||
// Take advantage of the information we've learned during
|
||||
// selector-matching.
|
||||
if !relations.intersects(AFFECTED_BY_PRESENTATIONAL_HINTS) {
|
||||
debug_assert!(cache.pres_hints.as_ref().map_or(true, |v| v.is_empty()));
|
||||
cache.pres_hints = Some(SmallVec::new());
|
||||
debug_assert!(validation_data.pres_hints.as_ref().map_or(true, |v| v.is_empty()));
|
||||
validation_data.pres_hints = Some(SmallVec::new());
|
||||
}
|
||||
|
||||
debug!("Inserting into cache: {:?} with parent {:?}", element, parent);
|
||||
|
||||
self.cache.insert(StyleSharingCandidate {
|
||||
element: unsafe { SendElement::new(*element) },
|
||||
cache: cache,
|
||||
validation_data: validation_data,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue