Bug 1448559: Cleanup CalcStyleDifference. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 24 Mar 2018 15:47:44 +0100
changeset 771996 9ab58656478fc5d2aaf095174d8e168db6e32939
parent 771993 f2dd14ef816f02a2333fe62cdd3fba870eee288c
child 772249 d822c3f4104b3fac67da4c6c992f9fbff783b55f
push id103823
push userbmo:emilio@crisal.io
push dateSat, 24 Mar 2018 14:49:36 +0000
reviewersxidorn
bugs1448559
milestone61.0a1
Bug 1448559: Cleanup CalcStyleDifference. r?xidorn The aSamePointerStructs argument is unused now. Also, aIgnoreVariables can be true everywhere now, since variable changes can't generate change hints, and anonymous boxes and such don't care about whether they really changed or not. Only one caller cares about struct equality, and that already compares variables manually as an optimization on the rust side. We had this optimization inconsistently in some cases but not others. MozReview-Commit-ID: F2EISKlxR3K
dom/animation/KeyframeEffectReadOnly.cpp
layout/base/ServoRestyleManager.cpp
layout/generic/nsFrame.cpp
layout/style/ComputedStyle.cpp
layout/style/ComputedStyle.h
layout/style/ServoBindings.cpp
layout/tables/nsTableFrame.cpp
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -1546,21 +1546,18 @@ KeyframeEffectReadOnly::CalculateCumulat
                                             segment.mToValue,
                                             aComputedStyle);
       if (!toContext) {
         mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
         return;
       }
 
       uint32_t equalStructs = 0;
-      uint32_t samePointerStructs = 0;
       nsChangeHint changeHint =
-        fromContext->CalcStyleDifference(toContext,
-                                         &equalStructs,
-                                         &samePointerStructs);
+        fromContext->CalcStyleDifference(toContext, &equalStructs);
 
       mCumulativeChangeHint |= changeHint;
     }
   }
 }
 
 void
 KeyframeEffectReadOnly::SetAnimation(Animation* aAnimation)
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -521,21 +521,18 @@ public:
 
     // We rely on the fact that all the text children for the same element share
     // style to avoid recomputing style differences for all of them.
     //
     // TODO(emilio): The above may not be true for ::first-{line,letter}, but
     // we'll cross that bridge when we support those in stylo.
     if (mShouldComputeHints) {
       mShouldComputeHints = false;
-      uint32_t equalStructs, samePointerStructs;
-      mComputedHint =
-        oldStyle->CalcStyleDifference(&aNewStyle,
-                                      &equalStructs,
-                                      &samePointerStructs);
+      uint32_t equalStructs;
+      mComputedHint = oldStyle->CalcStyleDifference(&aNewStyle, &equalStructs);
       mComputedHint = NS_RemoveSubsumedHints(
         mComputedHint, mParentRestyleState.ChangesHandledFor(*aTextFrame));
     }
 
     if (mComputedHint) {
       mParentRestyleState.ChangeList().AppendChange(
         aTextFrame, aContent, mComputedHint);
     }
@@ -638,21 +635,19 @@ UpdateOneAdditionalComputedStyle(nsIFram
 
   RefPtr<ComputedStyle> newContext =
     aRestyleState.StyleSet().ResolvePseudoElementStyle(
         aFrame->GetContent()->AsElement(),
         pseudoType,
         aFrame->Style(),
         /* aPseudoElement = */ nullptr);
 
-  uint32_t equalStructs, samePointerStructs; // Not used, actually.
-  nsChangeHint childHint = aOldContext.CalcStyleDifference(
-    newContext,
-    &equalStructs,
-    &samePointerStructs);
+  uint32_t equalStructs; // Not used, actually.
+  nsChangeHint childHint =
+    aOldContext.CalcStyleDifference(newContext, &equalStructs);
   if (!aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
     childHint = NS_RemoveSubsumedHints(
         childHint, aRestyleState.ChangesHandledFor(*aFrame));
   }
 
   if (childHint) {
     if (childHint & nsChangeHint_ReconstructFrame) {
       // If we generate a reconstruct here, remove any non-reconstruct hints we
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10758,22 +10758,20 @@ nsIFrame::UpdateStyleOfOwnedChildFrame(
   //
   // 1) Even if all the child's changes are due to properties it inherits from
   //    us, it's possible that no one ever asked us for those style structs and
   //    hence changes to them aren't reflected in the changes handled at all.
   //
   // 2) Content can change stylesheets that change the styles of pseudos, and
   //    extensions can add/remove stylesheets that change the styles of
   //    anonymous boxes directly.
-  uint32_t equalStructs, samePointerStructs; // Not used, actually.
+  uint32_t equalStructs; // Not used, actually.
   nsChangeHint childHint = aChildFrame->Style()->CalcStyleDifference(
     aNewComputedStyle,
-    &equalStructs,
-    &samePointerStructs,
-    /* aIgnoreVariables = */ true);
+    &equalStructs);
 
   // CalcStyleDifference will handle caching structs on the new style, but only
   // if we're not on a style worker thread.
   MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal(),
              "if we can get in here from style worker threads, then we need "
              "a ResolveSameStructsAs call to ensure structs are cached on "
              "aNewComputedStyle");
 
--- a/layout/style/ComputedStyle.cpp
+++ b/layout/style/ComputedStyle.cpp
@@ -21,22 +21,21 @@
 
 #include "nsCOMPtr.h"
 #include "nsIPresShell.h"
 
 #include "GeckoProfiler.h"
 #include "nsIDocument.h"
 #include "nsPrintfCString.h"
 #include "RubyUtils.h"
+#include "mozilla/ArenaObjectID.h"
+#include "mozilla/ComputedStyleInlines.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/ArenaObjectID.h"
 #include "mozilla/StyleSetHandle.h"
 #include "mozilla/StyleSetHandleInlines.h"
-#include "mozilla/ComputedStyle.h"
-#include "mozilla/ComputedStyleInlines.h"
 
 #include "mozilla/ReflowInput.h"
 #include "nsLayoutUtils.h"
 #include "nsCoord.h"
 
 // Ensure the binding function declarations in ComputedStyle.h matches
 // those in ServoBindings.h.
 #include "mozilla/ServoBindings.h"
@@ -102,69 +101,54 @@ ComputedStyle::ComputedStyle(nsPresConte
 
 #ifdef DEBUG
   static_assert(MOZ_ARRAY_LENGTH(ComputedStyle::sDependencyTable)
                   == nsStyleStructID_Length,
                 "Number of items in dependency table doesn't match IDs");
 #endif
 }
 
-// TODO(stylo-everywhere): Remove aSamePointerStructs.
 nsChangeHint
 ComputedStyle::CalcStyleDifference(ComputedStyle* aNewContext,
-                                    uint32_t* aEqualStructs,
-                                    uint32_t* aSamePointerStructs,
-                                    bool aIgnoreVariables)
+                                   uint32_t* aEqualStructs)
 {
   AUTO_PROFILER_LABEL("ComputedStyle::CalcStyleDifference", CSS);
 
   static_assert(nsStyleStructID_Length <= 32,
                 "aEqualStructs is not big enough");
 
   *aEqualStructs = 0;
-  *aSamePointerStructs = 0;
 
   nsChangeHint hint = nsChangeHint(0);
   NS_ENSURE_TRUE(aNewContext, hint);
   // We must always ensure that we populate the structs on the new style
   // context that are filled in on the old context, so that if we get
   // two style changes in succession, the second of which causes a real
   // style change, the PeekStyleData doesn't return null (implying that
   // nobody ever looked at that struct's data).  In other words, we
   // can't skip later structs if we get a big change up front, because
   // we could later get a small change in one of those structs that we
   // don't want to miss.
 
   DebugOnly<uint32_t> structsFound = 0;
 
-  if (aIgnoreVariables ||
-      Servo_ComputedValues_EqualCustomProperties(
-        ComputedData(),
-        aNewContext->ComputedData())) {
-    *aEqualStructs |= NS_STYLE_INHERIT_BIT(Variables);
-  }
-
+  *aEqualStructs |= NS_STYLE_INHERIT_BIT(Variables);
   DebugOnly<int> styleStructCount = 1;  // count Variables already
 
   // Servo's optimization to stop the cascade when there are no style changes
   // that children need to be recascade for relies on comparing all of the
   // structs, not just those that are returned from PeekStyleData, although
   // if PeekStyleData does return null we could avoid to accumulate any change
   // hints for those structs.
   //
   // FIXME(emilio): Reintroduce that optimization either for all kind of structs
   // after bug 1368290 with a weak parent pointer from text, or just for reset
   // structs.
-  //
-  // For Gecko structs, we just defer to PeekStyleXXX.  But for Servo structs,
-  // we need to use the aRelevantStructs bitfield passed in to determine
-  // whether to return a struct or not, since this->mBits might not yet
-  // be correct (due to not calling ResolveSameStructsAs on it yet).
-#define PEEK(struct_)                                                         \
-   ComputedData()->GetStyle##struct_()                                        \
+#define PEEK(struct_) \
+   ComputedData()->GetStyle##struct_()
 
 #define EXPAND(...) __VA_ARGS__
 #define DO_STRUCT_DIFFERENCE_WITH_ARGS(struct_, extra_args_)                  \
   PR_BEGIN_MACRO                                                              \
     const nsStyle##struct_* this##struct_ = PEEK(struct_);                    \
     if (this##struct_) {                                                      \
       structsFound |= NS_STYLE_INHERIT_BIT(struct_);                          \
                                                                               \
@@ -231,38 +215,16 @@ ComputedStyle::CalcStyleDifference(Compu
                (PEEK(name_) != nullptr),                                      \
                "PeekStyleData results must not change in the middle of "      \
                "difference calculation.");
   #include "nsStyleStructList.h"
   #undef STYLE_STRUCT
   #undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
 #endif
 
-  // We check for struct pointer equality here rather than as part of the
-  // DO_STRUCT_DIFFERENCE calls, since those calls can result in structs
-  // we previously examined and found to be null on this style context
-  // getting computed by later DO_STRUCT_DIFFERENCE calls (which can
-  // happen when the nsRuleNode::ComputeXXXData method looks up another
-  // struct.)  This is important for callers in RestyleManager that
-  // need to know the equality or not of the final set of cached struct
-  // pointers.
-  *aSamePointerStructs = 0;
-
-#define STYLE_STRUCT_LIST_IGNORE_VARIABLES
-#define STYLE_STRUCT(name_, callback_)                                        \
-  {                                                                           \
-    const nsStyle##name_* data = PEEK(name_);                                 \
-    if (!data || data == aNewContext->ThreadsafeStyle##name_()) {             \
-      *aSamePointerStructs |= NS_STYLE_INHERIT_BIT(name_);                    \
-    }                                                                         \
-  }
-#include "nsStyleStructList.h"
-#undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
-#undef STYLE_STRUCT
-
   // Note that we do not check whether this->RelevantLinkVisited() !=
   // aNewContext->RelevantLinkVisited(); we don't need to since
   // nsCSSFrameConstructor::DoContentStateChanged always adds
   // nsChangeHint_RepaintFrame for NS_EVENT_STATE_VISITED changes (and
   // needs to, since HasStateDependentStyle probably doesn't work right
   // for NS_EVENT_STATE_VISITED).  Hopefully this doesn't actually
   // expose whether links are visited to performance tests since all
   // link coloring happens asynchronously at a time when it's hard for
@@ -274,18 +236,17 @@ ComputedStyle::CalcStyleDifference(Compu
   // here, we add nsChangeHint_RepaintFrame hints (the maximum for
   // things that can depend on :visited) for the properties on which we
   // call GetVisitedDependentColor.
   ComputedStyle* thisVis = GetStyleIfVisited();
   ComputedStyle* otherVis = aNewContext->GetStyleIfVisited();
   if (!thisVis != !otherVis) {
     // One style has a style-if-visited and the other doesn't.
     // Presume a difference.
-#define STYLE_STRUCT(name_, fields_)                                \
-    *aSamePointerStructs &= ~NS_STYLE_INHERIT_BIT(name_);           \
+#define STYLE_STRUCT(name_, fields_) \
     *aEqualStructs &= ~NS_STYLE_INHERIT_BIT(name_);
 #include "nsCSSVisitedDependentPropList.h"
 #undef STYLE_STRUCT
     hint |= nsChangeHint_RepaintFrame;
   } else if (thisVis) {
     // Both styles have a style-if-visited.
     bool change = false;
 
@@ -297,17 +258,16 @@ ComputedStyle::CalcStyleDifference(Compu
 #define STYLE_FIELD(name_) thisVisStruct->name_ != otherVisStruct->name_
 #define STYLE_STRUCT(name_, fields_)                                    \
     if (PEEK(name_)) {                                                  \
       const nsStyle##name_* thisVisStruct =                             \
         thisVis->ThreadsafeStyle##name_();                              \
       const nsStyle##name_* otherVisStruct =                            \
         otherVis->ThreadsafeStyle##name_();                             \
       if (MOZ_FOR_EACH_SEPARATED(STYLE_FIELD, (||), (), fields_)) {     \
-        *aSamePointerStructs &= ~NS_STYLE_INHERIT_BIT(name_);           \
         *aEqualStructs &= ~NS_STYLE_INHERIT_BIT(name_);                 \
         change = true;                                                  \
       }                                                                 \
     }
 #include "nsCSSVisitedDependentPropList.h"
 #undef STYLE_STRUCT
 #undef STYLE_FIELD
 
--- a/layout/style/ComputedStyle.h
+++ b/layout/style/ComputedStyle.h
@@ -295,24 +295,22 @@ public:
    * This method returns a change hint (see nsChangeHint.h).  All change
    * hints apply to the frame and its later continuations or ib-split
    * siblings.  Most (all of those except the "NotHandledForDescendants"
    * hints) also apply to all descendants.
    *
    * aEqualStructs must not be null.  Into it will be stored a bitfield
    * representing which structs were compared to be non-equal.
    *
-   * aIgnoreVariables indicates whether to skip comparing the Variables
-   * struct.  This must only be true for Servo style contexts.  When
-   * true, the Variables bit in aEqualStructs will be set.
+   * CSS Variables are not compared here. Instead, the caller is responsible for
+   * that when needed (basically only for elements). The Variables bit in
+   * aEqualStructs is always set.
    */
   nsChangeHint CalcStyleDifference(ComputedStyle* aNewContext,
-                                   uint32_t* aEqualStructs,
-                                   uint32_t* aSamePointerStructs,
-				   bool aIgnoreVariables = false);
+                                   uint32_t* aEqualStructs);
 
 public:
   /**
    * Get a color that depends on link-visitedness using this and
    * this->GetStyleIfVisited().
    *
    * @param aField A pointer to a member variable in a style struct.
    *               The member variable and its style struct must have
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -360,23 +360,20 @@ Gecko_CalcStyleDifference(ComputedStyleB
                           ComputedStyleBorrowed aNewStyle,
                           bool* aAnyStyleChanged,
                           bool* aOnlyResetStructsChanged)
 {
   MOZ_ASSERT(aOldStyle);
   MOZ_ASSERT(aNewStyle);
 
   uint32_t equalStructs;
-  uint32_t samePointerStructs;  // unused
   nsChangeHint result = const_cast<mozilla::ComputedStyle*>(aOldStyle)->
     CalcStyleDifference(
       const_cast<mozilla::ComputedStyle*>(aNewStyle),
-      &equalStructs,
-      &samePointerStructs,
-      /* aIgnoreVariables = */ true);
+      &equalStructs);
 
   *aAnyStyleChanged = equalStructs != NS_STYLE_INHERIT_MASK;
 
   const uint32_t kInheritStructsMask =
     NS_STYLE_INHERIT_MASK & ~NS_STYLE_RESET_STRUCT_MASK;
 
   *aOnlyResetStructsChanged =
     (equalStructs & kInheritStructsMask) == kInheritStructsMask;
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -8197,22 +8197,20 @@ nsTableFrame::UpdateStyleOfOwnedAnonBoxe
   //
   // Also note that extensions can add/remove stylesheets that change the styles
   // of anonymous boxes directly, so we need to handle that potential change
   // here.
   //
   // NOTE(emilio): We can't use the ChangesHandledFor optimization (and we
   // assert against that), because the table wrapper is up in the frame tree
   // compared to the owner frame.
-  uint32_t equalStructs, samePointerStructs; // Not used, actually.
+  uint32_t equalStructs; // Not used, actually.
   nsChangeHint wrapperHint = aWrapperFrame->Style()->CalcStyleDifference(
     newContext,
-    &equalStructs,
-    &samePointerStructs,
-    /* aIgnoreVariables = */ true);
+    &equalStructs);
 
   // CalcStyleDifference will handle caching structs on the new style context,
   // but only if we're not on a style worker thread.
   MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal(),
              "if we can get in here from style worker threads, then we need "
              "a ResolveSameStructsAs call to ensure structs are cached on "
              "aNewComputedStyle");