Make replace_rules returning boolean.

We only use whether the return value is IMPORTANT_RULES_CHANGED or not, so we
can just return true if an important rules was changed in the function.
Also, we can just return false in case of animation rules changes sine for
animation we can ensure there is no importan rules.
Because of these changes, replace_rule_node does not borrow |result| so that
we can drop a scope there.
This commit is contained in:
Hiroyuki Ikezoe 2017-05-24 14:00:16 +09:00
parent fce7c2d885
commit a921d1af22
2 changed files with 55 additions and 59 deletions

View file

@ -972,33 +972,30 @@ pub trait MatchMethods : TElement {
}
/// Updates the rule nodes without re-running selector matching, using just
/// the rule tree. Returns RulesChanged which indicates whether the rule nodes changed
/// and whether the important rules changed.
/// the rule tree. Returns true if an !important rule was replaced.
fn replace_rules(&self,
replacements: RestyleReplacements,
context: &StyleContext<Self>,
data: &mut ElementData)
-> RulesChanged {
-> bool {
use properties::PropertyDeclarationBlock;
use shared_lock::Locked;
let element_styles = &mut data.styles_mut();
let primary_rules = &mut element_styles.primary.rules;
let mut result = RulesChanged::empty();
let mut result = false;
{
let mut replace_rule_node = |level: CascadeLevel,
let replace_rule_node = |level: CascadeLevel,
pdb: Option<&Arc<Locked<PropertyDeclarationBlock>>>,
path: &mut StrongRuleNode| {
path: &mut StrongRuleNode| -> bool {
let new_node = context.shared.stylist.rule_tree()
.update_rule_at_level(level, pdb, path, &context.shared.guards);
if let Some(n) = new_node {
match new_node {
Some(n) => {
*path = n;
if level.is_important() {
result.insert(IMPORTANT_RULES_CHANGED);
} else {
result.insert(NORMAL_RULES_CHANGED);
}
level.is_important()
},
None => false,
}
};
@ -1016,7 +1013,7 @@ pub trait MatchMethods : TElement {
primary_rules);
}
let mut replace_rule_node_for_animation = |level: CascadeLevel,
let replace_rule_node_for_animation = |level: CascadeLevel,
primary_rules: &mut StrongRuleNode| {
let animation_rule = self.get_animation_rule_by_cascade(level);
replace_rule_node(level,
@ -1037,14 +1034,13 @@ pub trait MatchMethods : TElement {
}
} else if replacements.contains(RESTYLE_STYLE_ATTRIBUTE) {
let style_attribute = self.style_attribute();
replace_rule_node(CascadeLevel::StyleAttributeNormal,
result |= replace_rule_node(CascadeLevel::StyleAttributeNormal,
style_attribute,
primary_rules);
replace_rule_node(CascadeLevel::StyleAttributeImportant,
result |= replace_rule_node(CascadeLevel::StyleAttributeImportant,
style_attribute,
primary_rules);
}
}
result
}

View file

@ -770,11 +770,11 @@ fn compute_style<E, D>(_traversal: &D,
)
}
CascadeWithReplacements(flags) => {
let rules_changed = element.replace_rules(flags, context, data);
let important_rules_changed = element.replace_rules(flags, context, data);
element.cascade_primary_and_pseudos(
context,
data,
rules_changed.important_rules_changed()
important_rules_changed
)
}
CascadeOnly => {