From e88ac040edf1929ccc45bc59367e041695997613 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 7 Mar 2017 13:51:33 -0800 Subject: [PATCH] servo: Merge #15837 - Return true in set_property only when declaration block is changed (from upsuper:bug1344135); r=emilio This is [bug 1344135](https://bugzilla.mozilla.org/show_bug.cgi?id=1344135). Source-Repo: https://github.com/servo/servo Source-Revision: b11847d86c4983b76a8e8dc11716dc66b66148d7 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 61d2b45dff60297c7f0937dab733d5fb5a582f06 --- servo/components/script/dom/cssstyledeclaration.rs | 6 ++---- .../components/style/properties/declaration_block.rs | 12 ++++++++---- servo/ports/geckolib/glue.rs | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/servo/components/script/dom/cssstyledeclaration.rs b/servo/components/script/dom/cssstyledeclaration.rs index 4d81d457f88c..f658ed5375e3 100644 --- a/servo/components/script/dom/cssstyledeclaration.rs +++ b/servo/components/script/dom/cssstyledeclaration.rs @@ -266,11 +266,9 @@ impl CSSStyleDeclaration { // Step 8 // Step 9 - // We could try to be better I guess? - *changed = !declarations.is_empty(); + *changed = false; for declaration in declarations { - // TODO(emilio): We could check it changed - pdb.set_parsed_declaration(declaration.0, importance); + *changed |= pdb.set_parsed_declaration(declaration.0, importance); } Ok(()) diff --git a/servo/components/style/properties/declaration_block.rs b/servo/components/style/properties/declaration_block.rs index 949de6bd38ec..ac618dcbf723 100644 --- a/servo/components/style/properties/declaration_block.rs +++ b/servo/components/style/properties/declaration_block.rs @@ -171,10 +171,11 @@ impl PropertyDeclarationBlock { } /// Adds or overrides the declaration for a given property in this block, - /// without taking into account any kind of priority. + /// without taking into account any kind of priority. Returns whether the + /// declaration block is actually changed. pub fn set_parsed_declaration(&mut self, declaration: PropertyDeclaration, - importance: Importance) { + importance: Importance) -> bool { for slot in &mut *self.declarations { if slot.0.id() == declaration.id() { match (slot.1, importance) { @@ -184,10 +185,12 @@ impl PropertyDeclarationBlock { (Importance::Important, Importance::Normal) => { self.important_count -= 1; } - _ => {} + _ => if slot.0 == declaration { + return false; + } } *slot = (declaration, importance); - return + return true; } } @@ -195,6 +198,7 @@ impl PropertyDeclarationBlock { if importance.important() { self.important_count += 1; } + true } /// Set the declaration importance for a given property, if found. diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 8c3584c1026d..4dccb916c72c 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -837,10 +837,11 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro Box::new(StdoutErrorReporter), extra_data) { let mut declarations = RwLock::::as_arc(&declarations).write(); let importance = if is_important { Importance::Important } else { Importance::Normal }; + let mut changed = false; for decl in decls.into_iter() { - declarations.set_parsed_declaration(decl.0, importance); + changed |= declarations.set_parsed_declaration(decl.0, importance); } - true + changed } else { false }