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 605984 d3e1ccba9fa09207554ff18b4a371dba7e02e769
parent 605983 b2a8081b12557cabf59fb7d9e51786ed1f2ef016
child 636646 c0218bcaab0d501ca04dfc57c90864f9128d29ef
push id67572
push userbbirtles@mozilla.com
push dateMon, 10 Jul 2017 06:46:44 +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,30 @@ 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) {
+    bool skipRestyle;
+    // Update hashtable first in case PostRestyleForAnimation mutates it.
+    // (It shouldn't, but just to be sure.)
+    if (auto p = elementsToRestyle.LookupForAdd(key)) {
+      skipRestyle = p.Data();
+      p.Data() = true;
+    } else {
+      skipRestyle = false;
+      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);