style: Make RuleTree::root return a reference instead of a strong pointer.

There's no reason it wasn't done before.

MozReview-Commit-ID: G0lMLWmfHbS
This commit is contained in:
Emilio Cobos Álvarez 2017-07-09 21:02:21 +02:00
parent cc94a8b7cb
commit fcf85e4658
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 37 additions and 48 deletions

View file

@ -150,8 +150,8 @@ impl RuleTree {
}
/// Get the root rule node.
pub fn root(&self) -> StrongRuleNode {
self.root.clone()
pub fn root(&self) -> &StrongRuleNode {
&self.root
}
fn dump<W: Write>(&self, guards: &StylesheetGuards, writer: &mut W) {
@ -171,11 +171,13 @@ impl RuleTree {
/// !important rules are detected and inserted into the appropriate position
/// in the rule tree. This allows selector matching to ignore importance,
/// while still maintaining the appropriate cascade order in the rule tree.
pub fn insert_ordered_rules_with_important<'a, I>(&self,
iter: I,
guards: &StylesheetGuards)
-> StrongRuleNode
where I: Iterator<Item=(StyleSource, CascadeLevel)>,
pub fn insert_ordered_rules_with_important<'a, I>(
&self,
iter: I,
guards: &StylesheetGuards
) -> StrongRuleNode
where
I: Iterator<Item=(StyleSource, CascadeLevel)>,
{
use self::CascadeLevel::*;
let mut current = self.root.clone();
@ -257,11 +259,11 @@ impl RuleTree {
/// Given a list of applicable declarations, insert the rules and return the
/// corresponding rule node.
pub fn compute_rule_node(&self,
applicable_declarations: &mut ApplicableDeclarationList,
guards: &StylesheetGuards)
-> StrongRuleNode
{
pub fn compute_rule_node(
&self,
applicable_declarations: &mut ApplicableDeclarationList,
guards: &StylesheetGuards
) -> StrongRuleNode {
let rules = applicable_declarations.drain().map(|d| d.order_and_level());
let rule_node = self.insert_ordered_rules_with_important(rules, guards);
rule_node

View file

@ -21,7 +21,7 @@ use properties::{self, CascadeFlags, ComputedValues};
use properties::{AnimationRules, PropertyDeclarationBlock};
#[cfg(feature = "servo")]
use properties::INHERIT_ALL;
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
use selector_map::{SelectorMap, SelectorMapEntry};
use selector_parser::{SelectorImpl, PseudoElement};
use selectors::attr::NamespaceConstraint;
@ -607,13 +607,12 @@ impl Stylist {
let rule_node = match self.precomputed_pseudo_element_decls.get(pseudo) {
Some(declarations) => {
// FIXME(emilio): When we've taken rid of the cascade we can just
// use into_iter.
self.rule_tree.insert_ordered_rules_with_important(
declarations.into_iter().map(|a| (a.source.clone(), a.level())),
guards)
guards
)
}
None => self.rule_tree.root(),
None => self.rule_tree.root().clone(),
};
// NOTE(emilio): We skip calculating the proper layout parent style
@ -757,13 +756,7 @@ impl Stylist {
// We may not have non-visited rules, if we only had visited ones. In
// that case we want to use the root rulenode for our non-visited rules.
let root;
let rules = if let Some(rules) = inputs.get_rules() {
rules
} else {
root = self.rule_tree.root();
&root
};
let rules = inputs.get_rules().unwrap_or(self.rule_tree.root());
// Read the comment on `precomputed_values_for_pseudo` to see why it's
// difficult to assert that display: contents nodes never arrive here
@ -839,25 +832,25 @@ impl Stylist {
MatchingContext::new(MatchingMode::ForStatelessPseudoElement,
None,
self.quirks_mode);
self.push_applicable_declarations(element,
Some(&pseudo),
None,
None,
AnimationRules(None, None),
rule_inclusion,
&mut declarations,
&mut matching_context,
&mut set_selector_flags);
self.push_applicable_declarations(
element,
Some(&pseudo),
None,
None,
AnimationRules(None, None),
rule_inclusion,
&mut declarations,
&mut matching_context,
&mut set_selector_flags
);
if !declarations.is_empty() {
let rule_node = self.rule_tree.insert_ordered_rules_with_important(
declarations.into_iter().map(|a| a.order_and_level()),
guards);
if rule_node != self.rule_tree.root() {
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited,
rule_node);
}
};
let rule_node =
self.rule_tree.compute_rule_node(&mut declarations, guards);
debug_assert!(rule_node != *self.rule_tree.root());
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited, rule_node);
}
if is_probe && !inputs.has_rules() {
// When probing, don't compute visited styles if we have no
@ -886,7 +879,7 @@ impl Stylist {
self.rule_tree.insert_ordered_rules_with_important(
declarations.into_iter().map(|a| a.order_and_level()),
guards);
if rule_node != self.rule_tree.root() {
if rule_node != *self.rule_tree.root() {
inputs.set_rules(VisitedHandlingMode::RelevantLinkVisited,
rule_node);
}
@ -1295,12 +1288,6 @@ impl Stylist {
&self.animations
}
/// Returns the rule root node.
#[inline]
pub fn rule_tree_root(&self) -> StrongRuleNode {
self.rule_tree.root()
}
/// Computes the match results of a given element against the set of
/// revalidation selectors.
pub fn match_revalidation_selectors<E, F>(&self,