Bug 1269901 - Remove mCachedMargin. r=dbaron
authorBobby Holley <bobbyholley@gmail.com>
Tue, 03 May 2016 15:08:05 -0700
changeset 296149 581279cd287e34b4af6b2544daff4589b6a2e580
parent 296148 1abdf346b87259240c11f24ed9fe0165165d916a
child 296150 2d50de084439d47a51753495052eff15774b1e40
push id76222
push userbholley@mozilla.com
push dateWed, 04 May 2016 23:56:22 +0000
treeherdermozilla-inbound@581279cd287e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1269901
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1269901 - Remove mCachedMargin. r=dbaron
layout/forms/nsButtonFrameRenderer.cpp
layout/generic/nsFrame.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/forms/nsButtonFrameRenderer.cpp
+++ b/layout/forms/nsButtonFrameRenderer.cpp
@@ -404,19 +404,17 @@ nsButtonFrameRenderer::GetButtonBorderAn
  */
 nsMargin
 nsButtonFrameRenderer::GetButtonInnerFocusMargin()
 {
   nsMargin innerFocusMargin(0,0,0,0);
 
   if (mInnerFocusStyle) {
     const nsStyleMargin* margin = mInnerFocusStyle->StyleMargin();
-    if (!margin->GetMargin(innerFocusMargin)) {
-      NS_NOTYETIMPLEMENTED("percentage margin");
-    }
+    margin->GetMarginNoPercentage(innerFocusMargin);
   }
 
   return innerFocusMargin;
 }
 
 nsMargin
 nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
 {
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -961,18 +961,17 @@ nsIFrame::GetUsedMargin() const
       IsSVGText())
     return margin;
 
   nsMargin *m = static_cast<nsMargin*>
                            (Properties().Get(UsedMarginProperty()));
   if (m) {
     margin = *m;
   } else {
-    DebugOnly<bool> hasMargin = StyleMargin()->GetMargin(margin);
-    NS_ASSERTION(hasMargin, "We should have a margin here! (out of memory?)");
+    StyleMargin()->GetMarginNoPercentage(margin);
   }
   return margin;
 }
 
 /* virtual */ nsMargin
 nsIFrame::GetUsedBorder() const
 {
   nsMargin border(0, 0, 0, 0);
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7212,17 +7212,16 @@ nsRuleNode::ComputeMarginData(void* aSta
                  coord, parentCoord,
                  SETCOORD_LPAH | SETCOORD_INITIAL_ZERO | SETCOORD_STORE_CALC |
                    SETCOORD_UNSET_INITIAL,
                  aContext, mPresContext, conditions)) {
       margin->mMargin.Set(side, coord);
     }
   }
 
-  margin->RecalcData();
   COMPUTE_END_RESET(Margin, margin)
 }
 
 static void
 SetBorderImageRect(const nsCSSValue& aValue,
                    /** outparam */ nsCSSRect& aRect)
 {
   switch (aValue.GetUnit()) {
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -250,54 +250,37 @@ static nscoord CalcCoord(const nsStyleCo
     NS_NOTREACHED("unexpected enum value");
     return 0;
   }
   MOZ_ASSERT(aCoord.ConvertsToLength(), "unexpected unit");
   return nsRuleNode::ComputeCoordPercentCalc(aCoord, 0);
 }
 
 nsStyleMargin::nsStyleMargin(StyleStructContext aContext)
-  : mHasCachedMargin(false)
-  , mCachedMargin(0, 0, 0, 0)
 {
   MOZ_COUNT_CTOR(nsStyleMargin);
   nsStyleCoord zero(0, nsStyleCoord::CoordConstructor);
   NS_FOR_CSS_SIDES(side) {
     mMargin.Set(side, zero);
   }
 }
 
 nsStyleMargin::nsStyleMargin(const nsStyleMargin& aSrc)
   : mMargin(aSrc.mMargin)
-  , mHasCachedMargin(false)
-  , mCachedMargin(0, 0, 0, 0)
 {
   MOZ_COUNT_CTOR(nsStyleMargin);
 }
 
 void 
 nsStyleMargin::Destroy(nsPresContext* aContext) {
   this->~nsStyleMargin();
   aContext->PresShell()->
     FreeByObjectID(eArenaObjectID_nsStyleMargin, this);
 }
 
-
-void nsStyleMargin::RecalcData()
-{
-  if (mMargin.ConvertsToLength()) {
-    NS_FOR_CSS_SIDES(side) {
-      mCachedMargin.Side(side) = CalcCoord(mMargin.Get(side), nullptr, 0);
-    }
-    mHasCachedMargin = true;
-  }
-  else
-    mHasCachedMargin = false;
-}
-
 nsChangeHint nsStyleMargin::CalcDifference(const nsStyleMargin& aOther) const
 {
   if (mMargin == aOther.mMargin) {
     return NS_STYLE_HINT_NONE;
   }
   // Margin differences can't affect descendant intrinsic sizes and
   // don't need to force children to reflow.
   return nsChangeHint_NeedReflow |
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -848,44 +848,51 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
 
   void* operator new(size_t sz, nsStyleMargin* aSelf) CPP_THROW_NEW { return aSelf; }
   void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
     return aContext->PresShell()->
       AllocateByObjectID(mozilla::eArenaObjectID_nsStyleMargin, sz);
   }
   void Destroy(nsPresContext* aContext);
 
-  void RecalcData();
   nsChangeHint CalcDifference(const nsStyleMargin& aOther) const;
   static nsChangeHint MaxDifference() {
     return nsChangeHint_NeedReflow |
            nsChangeHint_ReflowChangesSizeOrPosition |
            nsChangeHint_ClearAncestorIntrinsics;
   }
   static nsChangeHint DifferenceAlwaysHandledForDescendants() {
     // CalcDifference can return all of the reflow hints sometimes not
     // handled for descendants as hints not handled for descendants.
     return nsChangeHint(0);
   }
 
   nsStyleSides  mMargin;          // [reset] coord, percent, calc, auto
 
-  bool IsWidthDependent() const { return !mHasCachedMargin; }
+  bool IsWidthDependent() const {
+    return !mMargin.ConvertsToLength();
+  }
+
   bool GetMargin(nsMargin& aMargin) const
   {
-    if (mHasCachedMargin) {
-      aMargin = mCachedMargin;
+    if (mMargin.ConvertsToLength()) {
+      GetMarginNoPercentage(aMargin);
       return true;
     }
+
     return false;
   }
 
-protected:
-  bool          mHasCachedMargin;
-  nsMargin      mCachedMargin;
+  void GetMarginNoPercentage(nsMargin& aMargin) const
+  {
+    MOZ_ASSERT(mMargin.ConvertsToLength());
+    NS_FOR_CSS_SIDES(side) {
+      aMargin.Side(side) = mMargin.Get(side).ToLength();
+    }
+  }
 };
 
 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePadding
 {
   explicit nsStylePadding(StyleStructContext aContext);
   nsStylePadding(const nsStylePadding& aPadding);
   ~nsStylePadding() {
     MOZ_COUNT_DTOR(nsStylePadding);