Bug 1376594 - Coalesce two hashmap lookups in EffectCompositor::RequestRestyle; r?mats draft
authorBrian Birtles <birtles@gmail.com>
Wed, 05 Jul 2017 10:30:44 +0900
changeset 603958 028470b4a6ba1994f061232770c0f3647c73066a
parent 603957 89f2f2f1a60973a4e4497242c13a9e1ee4621972
child 636049 4a6ba27c8169dd078fb7fef21596402018c1f036
push id66915
push userbbirtles@mozilla.com
push dateWed, 05 Jul 2017 02:53:28 +0000
reviewersmats
bugs1376594
milestone56.0a1
Bug 1376594 - Coalesce two hashmap lookups in EffectCompositor::RequestRestyle; r?mats MozReview-Commit-ID: 4TyFKwtcDEz
dom/animation/EffectCompositor.cpp
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -266,23 +266,31 @@ EffectCompositor::RequestRestyle(dom::El
 
   auto& elementsToRestyle = mElementsToRestyle[aCascadeLevel];
   PseudoElementHashEntry::KeyType key = { aElement, aPseudoType };
 
   if (aRestyleType == RestyleType::Throttled) {
     elementsToRestyle.LookupForAdd(key).OrInsert([]() { return false; });
     mPresContext->PresShell()->SetNeedThrottledAnimationFlush();
   } else {
-    // Get() returns 0 if the element is not found. It will also return
-    // false if the element is found but does not have a pending restyle.
-    bool hasPendingRestyle = elementsToRestyle.Get(key);
-    if (!hasPendingRestyle) {
+    auto p = elementsToRestyle.LookupForAdd(key);
+    bool skipRestyle =  false;
+    // Update hashtable first in case PostRestyleForAnimation mutates it.
+    // (It shouldn't, but just to be sure.)
+    if (p) {
+      if (p.Data()) {
+        skipRestyle = true;
+      }
+      p.Data() = true;
+    } else {
+      p.OrInsert([]() { return true; });
+    }
+    if (!skipRestyle) {
       PostRestyleForAnimation(aElement, aPseudoType, aCascadeLevel);
     }
-    elementsToRestyle.Put(key, true);
   }
 
   if (aRestyleType == RestyleType::Layer) {
     mPresContext->RestyleManager()->IncrementAnimationGeneration();
     EffectSet* effectSet =
       EffectSet::GetEffectSet(aElement, aPseudoType);
     if (effectSet) {
       effectSet->UpdateAnimationGeneration(mPresContext);