From a921d1af224cba485c217dc3480a9acb072bc6d1 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Wed, 24 May 2017 14:00:16 +0900 Subject: [PATCH] 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. --- components/style/matching.rs | 110 ++++++++++++++++------------------ components/style/traversal.rs | 4 +- 2 files changed, 55 insertions(+), 59 deletions(-) diff --git a/components/style/matching.rs b/components/style/matching.rs index e11141e8d63..61130b7d609 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -972,78 +972,74 @@ 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, 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, - pdb: Option<&Arc>>, - path: &mut StrongRuleNode| { - let new_node = context.shared.stylist.rule_tree() - .update_rule_at_level(level, pdb, path, &context.shared.guards); - if let Some(n) = new_node { + let replace_rule_node = |level: CascadeLevel, + pdb: Option<&Arc>>, + path: &mut StrongRuleNode| -> bool { + let new_node = context.shared.stylist.rule_tree() + .update_rule_at_level(level, pdb, path, &context.shared.guards); + 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, + } + }; - // Animation restyle hints are processed prior to other restyle - // hints in the animation-only traversal. - // - // Non-animation restyle hints will be processed in a subsequent - // normal traversal. - if replacements.intersects(RestyleReplacements::for_animations()) { - debug_assert!(context.shared.traversal_flags.for_animation_only()); + // Animation restyle hints are processed prior to other restyle + // hints in the animation-only traversal. + // + // Non-animation restyle hints will be processed in a subsequent + // normal traversal. + if replacements.intersects(RestyleReplacements::for_animations()) { + debug_assert!(context.shared.traversal_flags.for_animation_only()); - if replacements.contains(RESTYLE_SMIL) { - replace_rule_node(CascadeLevel::SMILOverride, - self.get_smil_override(), - primary_rules); - } - - let mut 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, - animation_rule.as_ref(), - primary_rules); - }; - - // Apply Transition rules and Animation rules if the corresponding restyle hint - // is contained. - if replacements.contains(RESTYLE_CSS_TRANSITIONS) { - replace_rule_node_for_animation(CascadeLevel::Transitions, - primary_rules); - } - - if replacements.contains(RESTYLE_CSS_ANIMATIONS) { - replace_rule_node_for_animation(CascadeLevel::Animations, - primary_rules); - } - } else if replacements.contains(RESTYLE_STYLE_ATTRIBUTE) { - let style_attribute = self.style_attribute(); - replace_rule_node(CascadeLevel::StyleAttributeNormal, - style_attribute, - primary_rules); - replace_rule_node(CascadeLevel::StyleAttributeImportant, - style_attribute, + if replacements.contains(RESTYLE_SMIL) { + replace_rule_node(CascadeLevel::SMILOverride, + self.get_smil_override(), primary_rules); } + + 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, + animation_rule.as_ref(), + primary_rules); + }; + + // Apply Transition rules and Animation rules if the corresponding restyle hint + // is contained. + if replacements.contains(RESTYLE_CSS_TRANSITIONS) { + replace_rule_node_for_animation(CascadeLevel::Transitions, + primary_rules); + } + + if replacements.contains(RESTYLE_CSS_ANIMATIONS) { + replace_rule_node_for_animation(CascadeLevel::Animations, + primary_rules); + } + } else if replacements.contains(RESTYLE_STYLE_ATTRIBUTE) { + let style_attribute = self.style_attribute(); + result |= replace_rule_node(CascadeLevel::StyleAttributeNormal, + style_attribute, + primary_rules); + result |= replace_rule_node(CascadeLevel::StyleAttributeImportant, + style_attribute, + primary_rules); } result diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 6e6ccf813a1..146069b1bc3 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -770,11 +770,11 @@ fn compute_style(_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 => {