Bug 1372068: Move one-off checks out of the recursive function. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 12 Jun 2017 04:56:31 +0200
changeset 592330 e169eae51f8dde42f777191e44fb3c2a2ea59144
parent 592329 9522873f7f709d8badc2681927a0589433327a2b
child 632776 69173be9b667441de954709967cf6b370d1075b9
push id63341
push userbmo:emilio+bugs@crisal.io
push dateMon, 12 Jun 2017 03:00:20 +0000
reviewersheycam
bugs1372068
milestone55.0a1
Bug 1372068: Move one-off checks out of the recursive function. r?heycam There isn't a need to pay the cost for them multiple times. MozReview-Commit-ID: 3K2mRcWTheJ
servo/components/style/invalidation/stylesheets.rs
--- a/servo/components/style/invalidation/stylesheets.rs
+++ b/servo/components/style/invalidation/stylesheets.rs
@@ -110,22 +110,47 @@ impl StylesheetInvalidationSet {
     }
 
     /// Clears the invalidation set, invalidating elements as needed if
     /// `document_element` is provided.
     pub fn flush<E>(&mut self, document_element: Option<E>)
         where E: TElement,
     {
         if let Some(e) = document_element {
-            self.process_invalidations_in_subtree(e);
+            self.process_invalidations(e);
         }
         self.invalid_scopes.clear();
         self.fully_invalid = false;
     }
 
+    fn process_invalidations<E>(&self, element: E) -> bool
+        where E: TElement,
+    {
+        {
+            let mut data = match element.mutate_data() {
+                Some(data) => data,
+                None => return false,
+            };
+
+            if self.fully_invalid {
+                debug!("process_invalidations: fully_invalid({:?})",
+                       element);
+                data.ensure_restyle().hint.insert(StoredRestyleHint::subtree());
+                return true;
+            }
+        }
+
+        if self.invalid_scopes.is_empty() {
+            debug!("process_invalidations: empty invalidation set");
+            return false;
+        }
+
+        self.process_invalidations_in_subtree(element)
+    }
+
     /// Process style invalidations in a given subtree, that is, look for all
     /// the relevant scopes in the subtree, and mark as dirty only the relevant
     /// ones.
     ///
     /// Returns whether it invalidated at least one element's style.
     #[allow(unsafe_code)]
     fn process_invalidations_in_subtree<E>(&self, element: E) -> bool
         where E: TElement,
@@ -142,28 +167,16 @@ impl StylesheetInvalidationSet {
         if let Some(ref r) = data.get_restyle() {
             if r.hint.contains_subtree() {
                 debug!("process_invalidations_in_subtree: {:?} was already invalid",
                        element);
                 return false;
             }
         }
 
-        if self.fully_invalid {
-            debug!("process_invalidations_in_subtree: fully_invalid({:?})",
-                   element);
-            data.ensure_restyle().hint.insert(StoredRestyleHint::subtree());
-            return true;
-        }
-
-        if self.invalid_scopes.is_empty() {
-            debug!("process_invalidations_in_subtree: empty invalidation set");
-            return false;
-        }
-
         for scope in &self.invalid_scopes {
             if scope.matches(element) {
                 debug!("process_invalidations_in_subtree: {:?} matched {:?}",
                        element, scope);
                 data.ensure_restyle().hint.insert(StoredRestyleHint::subtree());
                 return true;
             }
         }