Rearrange compute_style and eliminate MatchResults.

This simplifies things by avoiding the computation of MatchResults when we
don't need them.

We continue to compute rule_nodes_changed, even though we don't use it
for the moment, since we will need it soon for various incremental restyle
optimizations.

MozReview-Commit-ID: 4qsUYaD5Bs2
This commit is contained in:
Bobby Holley 2017-04-05 18:55:09 -07:00
parent 42f5aea76a
commit 19743a67ba
2 changed files with 23 additions and 48 deletions

View file

@ -30,7 +30,7 @@ use stylist::ApplicableDeclarationBlock;
/// Determines the amount of relations where we're going to share style. /// Determines the amount of relations where we're going to share style.
#[inline] #[inline]
fn relations_are_shareable(relations: &StyleRelations) -> bool { pub fn relations_are_shareable(relations: &StyleRelations) -> bool {
use selectors::matching::*; use selectors::matching::*;
!relations.intersects(AFFECTED_BY_ID_SELECTOR | !relations.intersects(AFFECTED_BY_ID_SELECTOR |
AFFECTED_BY_PSEUDO_ELEMENTS | AFFECTED_BY_STATE | AFFECTED_BY_PSEUDO_ELEMENTS | AFFECTED_BY_STATE |
@ -58,24 +58,6 @@ fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &
flags flags
} }
/// The results returned from running selector matching on an element.
pub struct MatchResults {
/// A set of style relations (different hints about what rules matched or
/// could have matched). This is necessary if the style will be shared.
/// If None, the style will not be shared.
pub primary_relations: Option<StyleRelations>,
/// Whether the rule nodes changed during selector matching.
pub rule_nodes_changed: bool,
}
impl MatchResults {
/// Returns true if the primary rule node is shareable with other nodes.
pub fn primary_is_shareable(&self) -> bool {
self.primary_relations.as_ref()
.map_or(false, relations_are_shareable)
}
}
/// Information regarding a style sharing candidate. /// Information regarding a style sharing candidate.
/// ///
/// Note that this information is stored in TLS and cleared after the traversal, /// Note that this information is stored in TLS and cleared after the traversal,
@ -799,7 +781,7 @@ pub trait MatchMethods : TElement {
fn match_element(&self, fn match_element(&self,
context: &mut StyleContext<Self>, context: &mut StyleContext<Self>,
data: &mut ElementData) data: &mut ElementData)
-> MatchResults -> (StyleRelations, bool)
{ {
let mut applicable_declarations = let mut applicable_declarations =
Vec::<ApplicableDeclarationBlock>::with_capacity(16); Vec::<ApplicableDeclarationBlock>::with_capacity(16);
@ -887,10 +869,7 @@ pub trait MatchMethods : TElement {
primary_relations |= AFFECTED_BY_PSEUDO_ELEMENTS; primary_relations |= AFFECTED_BY_PSEUDO_ELEMENTS;
} }
MatchResults { (primary_relations, rule_nodes_changed)
primary_relations: Some(primary_relations),
rule_nodes_changed: rule_nodes_changed,
}
} }
/// Applies selector flags to an element, deferring mutations of the parent /// Applies selector flags to an element, deferring mutations of the parent

View file

@ -10,7 +10,8 @@ use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use context::{SharedStyleContext, StyleContext, ThreadLocalStyleContext}; use context::{SharedStyleContext, StyleContext, ThreadLocalStyleContext};
use data::{ElementData, ElementStyles, StoredRestyleHint}; use data::{ElementData, ElementStyles, StoredRestyleHint};
use dom::{DirtyDescendants, NodeInfo, TElement, TNode}; use dom::{DirtyDescendants, NodeInfo, TElement, TNode};
use matching::{MatchMethods, MatchResults}; use matching::MatchMethods;
use matching::relations_are_shareable;
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_SELF}; use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_SELF};
use selector_parser::RestyleDamage; use selector_parser::RestyleDamage;
use servo_config::opts; use servo_config::opts;
@ -586,7 +587,7 @@ fn compute_style<E, D>(_traversal: &D,
} }
} }
let match_results = match kind { match kind {
MatchAndCascade => { MatchAndCascade => {
// Ensure the bloom filter is up to date. // Ensure the bloom filter is up to date.
let dom_depth = let dom_depth =
@ -605,35 +606,30 @@ fn compute_style<E, D>(_traversal: &D,
// Perform CSS selector matching. // Perform CSS selector matching.
context.thread_local.statistics.elements_matched += 1; context.thread_local.statistics.elements_matched += 1;
element.match_element(context, &mut data) let (primary_relations, _rule_nodes_changed) =
element.match_element(context, &mut data);
// Cascade properties and compute values.
element.cascade_element(context, &mut data);
// If the style is shareable, add it to the LRU cache.
if relations_are_shareable(&primary_relations) {
context.thread_local
.style_sharing_candidate_cache
.insert_if_possible(&element,
data.styles().primary.values(),
primary_relations);
}
} }
CascadeWithReplacements(hint) => { CascadeWithReplacements(hint) => {
let rule_nodes_changed = let _rule_nodes_changed =
element.cascade_with_replacements(hint, context, &mut data); element.cascade_with_replacements(hint, context, &mut data);
MatchResults { element.cascade_element(context, &mut data);
primary_relations: None,
rule_nodes_changed: rule_nodes_changed,
}
} }
CascadeOnly => { CascadeOnly => {
MatchResults { element.cascade_element(context, &mut data);
primary_relations: None,
rule_nodes_changed: false,
}
} }
}; };
// Cascade properties and compute values.
element.cascade_element(context, &mut data);
// If the style is shareable, add it to the LRU cache.
if match_results.primary_is_shareable() {
context.thread_local
.style_sharing_candidate_cache
.insert_if_possible(&element,
data.styles().primary.values(),
match_results.primary_relations.unwrap());
}
} }
fn preprocess_children<E, D>(traversal: &D, fn preprocess_children<E, D>(traversal: &D,