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.
#[inline]
fn relations_are_shareable(relations: &StyleRelations) -> bool {
pub fn relations_are_shareable(relations: &StyleRelations) -> bool {
use selectors::matching::*;
!relations.intersects(AFFECTED_BY_ID_SELECTOR |
AFFECTED_BY_PSEUDO_ELEMENTS | AFFECTED_BY_STATE |
@ -58,24 +58,6 @@ fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &
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.
///
/// 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,
context: &mut StyleContext<Self>,
data: &mut ElementData)
-> MatchResults
-> (StyleRelations, bool)
{
let mut applicable_declarations =
Vec::<ApplicableDeclarationBlock>::with_capacity(16);
@ -887,10 +869,7 @@ pub trait MatchMethods : TElement {
primary_relations |= AFFECTED_BY_PSEUDO_ELEMENTS;
}
MatchResults {
primary_relations: Some(primary_relations),
rule_nodes_changed: rule_nodes_changed,
}
(primary_relations, rule_nodes_changed)
}
/// Applies selector flags to an element, deferring mutations of the parent