style: Move cached media query results into per-origin data.

This commit is contained in:
Cameron McCormack 2017-08-12 15:46:57 +08:00
parent f9d1a0e2d1
commit db6a09f24f
2 changed files with 29 additions and 13 deletions

View file

@ -52,6 +52,7 @@ impl ToMediaListKey for MediaRule {}
/// A struct that holds the result of a media query evaluation pass for the /// A struct that holds the result of a media query evaluation pass for the
/// media queries that evaluated successfully. /// media queries that evaluated successfully.
#[derive(Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct EffectiveMediaQueryResults { pub struct EffectiveMediaQueryResults {
/// The set of media lists that matched last time. /// The set of media lists that matched last time.

View file

@ -74,9 +74,6 @@ pub struct Stylist {
/// Viewport constraints based on the current device. /// Viewport constraints based on the current device.
viewport_constraints: Option<ViewportConstraints>, viewport_constraints: Option<ViewportConstraints>,
/// Effective media query results cached from the last rebuild.
effective_media_query_results: EffectiveMediaQueryResults,
/// If true, the quirks-mode stylesheet is applied. /// If true, the quirks-mode stylesheet is applied.
#[cfg_attr(feature = "servo", ignore_heap_size_of = "defined in selectors")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "defined in selectors")]
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
@ -144,7 +141,6 @@ impl Stylist {
is_device_dirty: true, is_device_dirty: true,
is_cleared: true, is_cleared: true,
quirks_mode: quirks_mode, quirks_mode: quirks_mode,
effective_media_query_results: EffectiveMediaQueryResults::new(),
cascade_data: Default::default(), cascade_data: Default::default(),
precomputed_pseudo_element_decls: PerPseudoElementMap::default(), precomputed_pseudo_element_decls: PerPseudoElementMap::default(),
@ -215,7 +211,6 @@ impl Stylist {
self.is_cleared = true; self.is_cleared = true;
self.effective_media_query_results.clear();
self.viewport_constraints = None; self.viewport_constraints = None;
// preserve current device // preserve current device
self.is_device_dirty = true; self.is_device_dirty = true;
@ -353,13 +348,14 @@ impl Stylist {
return; return;
} }
self.effective_media_query_results.saw_effective(stylesheet);
let origin = stylesheet.origin(guard); let origin = stylesheet.origin(guard);
let origin_cascade_data = let origin_cascade_data =
self.cascade_data.borrow_mut_for_origin(&origin); self.cascade_data.borrow_mut_for_origin(&origin);
origin_cascade_data
.effective_media_query_results
.saw_effective(stylesheet);
for rule in stylesheet.effective_rules(&self.device, guard) { for rule in stylesheet.effective_rules(&self.device, guard) {
match *rule { match *rule {
CssRule::Style(ref locked) => { CssRule::Style(ref locked) => {
@ -436,14 +432,18 @@ impl Stylist {
} }
CssRule::Import(ref lock) => { CssRule::Import(ref lock) => {
let import_rule = lock.read_with(guard); let import_rule = lock.read_with(guard);
self.effective_media_query_results.saw_effective(import_rule); origin_cascade_data
.effective_media_query_results
.saw_effective(import_rule);
// NOTE: effective_rules visits the inner stylesheet if // NOTE: effective_rules visits the inner stylesheet if
// appropriate. // appropriate.
} }
CssRule::Media(ref lock) => { CssRule::Media(ref lock) => {
let media_rule = lock.read_with(guard); let media_rule = lock.read_with(guard);
self.effective_media_query_results.saw_effective(media_rule); origin_cascade_data
.effective_media_query_results
.saw_effective(media_rule);
} }
CssRule::Keyframes(ref keyframes_rule) => { CssRule::Keyframes(ref keyframes_rule) => {
let keyframes_rule = keyframes_rule.read_with(guard); let keyframes_rule = keyframes_rule.read_with(guard);
@ -954,8 +954,14 @@ impl Stylist {
let effective_now = let effective_now =
stylesheet.is_effective_for_device(&self.device, guard); stylesheet.is_effective_for_device(&self.device, guard);
let origin = stylesheet.origin(guard);
let origin_cascade_data =
self.cascade_data.borrow_for_origin(&origin);
let effective_then = let effective_then =
self.effective_media_query_results.was_effective(stylesheet); origin_cascade_data
.effective_media_query_results
.was_effective(stylesheet);
if effective_now != effective_then { if effective_now != effective_then {
debug!(" > Stylesheet changed -> {}, {}", debug!(" > Stylesheet changed -> {}, {}",
@ -994,7 +1000,9 @@ impl Stylist {
import_rule.stylesheet import_rule.stylesheet
.is_effective_for_device(&self.device, guard); .is_effective_for_device(&self.device, guard);
let effective_then = let effective_then =
self.effective_media_query_results.was_effective(import_rule); origin_cascade_data
.effective_media_query_results
.was_effective(import_rule);
if effective_now != effective_then { if effective_now != effective_then {
debug!(" > @import rule changed {} -> {}", debug!(" > @import rule changed {} -> {}",
effective_then, effective_now); effective_then, effective_now);
@ -1011,7 +1019,9 @@ impl Stylist {
let effective_now = let effective_now =
mq.evaluate(&self.device, self.quirks_mode); mq.evaluate(&self.device, self.quirks_mode);
let effective_then = let effective_then =
self.effective_media_query_results.was_effective(media_rule); origin_cascade_data
.effective_media_query_results
.was_effective(media_rule);
if effective_now != effective_then { if effective_now != effective_then {
debug!(" > @media rule changed {} -> {}", debug!(" > @media rule changed {} -> {}",
effective_then, effective_now); effective_then, effective_now);
@ -1612,6 +1622,9 @@ struct CascadeData {
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
selectors_for_cache_revalidation: SelectorMap<RevalidationSelectorAndHashes>, selectors_for_cache_revalidation: SelectorMap<RevalidationSelectorAndHashes>,
/// Effective media query results cached from the last rebuild.
effective_media_query_results: EffectiveMediaQueryResults,
/// The total number of selectors. /// The total number of selectors.
num_selectors: usize, num_selectors: usize,
@ -1631,6 +1644,7 @@ impl CascadeData {
state_dependencies: ElementState::empty(), state_dependencies: ElementState::empty(),
mapped_ids: NonCountingBloomFilter::new(), mapped_ids: NonCountingBloomFilter::new(),
selectors_for_cache_revalidation: SelectorMap::new(), selectors_for_cache_revalidation: SelectorMap::new(),
effective_media_query_results: EffectiveMediaQueryResults::new(),
num_selectors: 0, num_selectors: 0,
num_declarations: 0, num_declarations: 0,
} }
@ -1660,6 +1674,7 @@ impl PerOriginClear for CascadeData {
self.state_dependencies = ElementState::empty(); self.state_dependencies = ElementState::empty();
self.mapped_ids.clear(); self.mapped_ids.clear();
self.selectors_for_cache_revalidation = SelectorMap::new(); self.selectors_for_cache_revalidation = SelectorMap::new();
self.effective_media_query_results.clear();
self.num_selectors = 0; self.num_selectors = 0;
self.num_declarations = 0; self.num_declarations = 0;
} }