Skip to content

Commit

Permalink
style: Move revalidation selectors into PerOriginCascadeData.
Browse files Browse the repository at this point in the history
  • Loading branch information
heycam committed Aug 9, 2017
1 parent 7936132 commit 76aac7f
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions components/style/stylist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ pub struct Stylist {
/// style rule appears in a stylesheet, needed to sort them by source order.
rules_source_order: u32,

/// Selectors that require explicit cache revalidation (i.e. which depend
/// on state that is not otherwise visible to the cache, like attributes or
/// tree-structural state like child index and pseudos).
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
selectors_for_cache_revalidation: SelectorMap<RevalidationSelectorAndHashes>,

/// The total number of selectors.
num_selectors: usize,

Expand Down Expand Up @@ -205,7 +199,6 @@ impl Stylist {
precomputed_pseudo_element_decls: PerPseudoElementMap::default(),
rules_source_order: 0,
rule_tree: RuleTree::new(),
selectors_for_cache_revalidation: SelectorMap::new(),
num_selectors: 0,
num_declarations: 0,
num_rebuilds: 0,
Expand All @@ -231,7 +224,8 @@ impl Stylist {

/// Returns the number of revalidation_selectors.
pub fn num_revalidation_selectors(&self) -> usize {
self.selectors_for_cache_revalidation.len()
self.cascade_data.iter_origins()
.map(|d| d.selectors_for_cache_revalidation.len()).sum()
}

/// Returns the number of entries in invalidation maps.
Expand Down Expand Up @@ -281,7 +275,6 @@ impl Stylist {
self.precomputed_pseudo_element_decls.clear();
self.rules_source_order = 0;
// We want to keep rule_tree around across stylist rebuilds.
self.selectors_for_cache_revalidation = SelectorMap::new();
self.num_selectors = 0;
self.num_declarations = 0;
// preserve num_rebuilds value, since it should stay across
Expand Down Expand Up @@ -486,7 +479,7 @@ impl Stylist {
selector.visit(&mut visitor);

if visitor.needs_revalidation {
self.selectors_for_cache_revalidation.insert(
origin_cascade_data.selectors_for_cache_revalidation.insert(
RevalidationSelectorAndHashes::new(selector.clone(), hashes),
self.quirks_mode);
}
Expand Down Expand Up @@ -1339,17 +1332,19 @@ impl Stylist {
// the lookups, which means that the bitvecs are comparable. We verify
// this in the caller by asserting that the bitvecs are same-length.
let mut results = BitVec::new();
self.selectors_for_cache_revalidation.lookup(
*element, self.quirks_mode, &mut |selector_and_hashes| {
results.push(matches_selector(&selector_and_hashes.selector,
selector_and_hashes.selector_offset,
Some(&selector_and_hashes.hashes),
element,
&mut matching_context,
flags_setter));
true
}
);
for origin_cascade_data in self.cascade_data.iter_origins() {
origin_cascade_data.selectors_for_cache_revalidation.lookup(
*element, self.quirks_mode, &mut |selector_and_hashes| {
results.push(matches_selector(&selector_and_hashes.selector,
selector_and_hashes.selector_offset,
Some(&selector_and_hashes.hashes),
element,
&mut matching_context,
flags_setter));
true
}
);
}

results
}
Expand Down Expand Up @@ -1687,6 +1682,12 @@ struct PerOriginCascadeData {
/// filter, and hence might be in one of our selector maps.
#[cfg_attr(feature = "servo", ignore_heap_size_of = "just an array")]
mapped_ids: NonCountingBloomFilter,

/// Selectors that require explicit cache revalidation (i.e. which depend
/// on state that is not otherwise visible to the cache, like attributes or
/// tree-structural state like child index and pseudos).
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
selectors_for_cache_revalidation: SelectorMap<RevalidationSelectorAndHashes>,
}

impl PerOriginCascadeData {
Expand All @@ -1700,6 +1701,7 @@ impl PerOriginCascadeData {
style_attribute_dependency: false,
state_dependencies: ElementState::empty(),
mapped_ids: NonCountingBloomFilter::new(),
selectors_for_cache_revalidation: SelectorMap::new(),
}
}

Expand All @@ -1720,6 +1722,7 @@ impl PerOriginCascadeData {
self.style_attribute_dependency = false;
self.state_dependencies = ElementState::empty();
self.mapped_ids.clear();
self.selectors_for_cache_revalidation = SelectorMap::new();
}

fn has_rules_for_pseudo(&self, pseudo: &PseudoElement) -> bool {
Expand Down

0 comments on commit 76aac7f

Please sign in to comment.