Bug 1448535 part 1 - Make nsMathMLmtdInnerFrame use UniquePtr for its StyleText. r?dholbert draft
authorXidorn Quan <me@upsuper.org>
Mon, 26 Mar 2018 11:51:57 +1100
changeset 772910 e2cbe41afd02b6321e2dd6d7e36f7ad1be59fdf2
parent 772875 0e265b32254390666e2a301760d3168f1c26c025
child 772911 f08304fc5116b30936b0a9cf023112c53ae2b5b8
push id104086
push userxquan@mozilla.com
push dateTue, 27 Mar 2018 05:15:17 +0000
reviewersdholbert
bugs1448535
milestone61.0a1
Bug 1448535 part 1 - Make nsMathMLmtdInnerFrame use UniquePtr for its StyleText. r?dholbert MozReview-Commit-ID: 6tuA3JC1FDV
layout/mathml/nsMathMLmtableFrame.cpp
layout/mathml/nsMathMLmtableFrame.h
--- a/layout/mathml/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/nsMathMLmtableFrame.cpp
@@ -1264,24 +1264,19 @@ NS_NewMathMLmtdInnerFrame(nsIPresShell* 
 {
   return new (aPresShell) nsMathMLmtdInnerFrame(aStyle);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtdInnerFrame)
 
 nsMathMLmtdInnerFrame::nsMathMLmtdInnerFrame(ComputedStyle* aStyle)
   : nsBlockFrame(aStyle, kClassID)
+  // Make a copy of the parent nsStyleText for later modification.
+  , mUniqueStyleText(MakeUnique<nsStyleText>(*StyleText()))
 {
-  // Make a copy of the parent nsStyleText for later modification.
-  mUniqueStyleText = new (PresContext()) nsStyleText(*StyleText());
-}
-
-nsMathMLmtdInnerFrame::~nsMathMLmtdInnerFrame()
-{
-  mUniqueStyleText->Destroy(PresContext());
 }
 
 void
 nsMathMLmtdInnerFrame::Reflow(nsPresContext*           aPresContext,
                               ReflowOutput&     aDesiredSize,
                               const ReflowInput& aReflowInput,
                               nsReflowStatus&          aStatus)
 {
@@ -1309,18 +1304,17 @@ nsStyleText* nsMathMLmtdInnerFrame::Styl
     // values, we simply repeat the last value.
     if (columnIndex < alignmentList->Length())
       alignment = alignmentList->ElementAt(columnIndex);
     else
       alignment = alignmentList->ElementAt(alignmentList->Length() - 1);
   }
 
   mUniqueStyleText->mTextAlign = alignment;
-  return mUniqueStyleText;
+  return mUniqueStyleText.get();
 }
 
 /* virtual */ void
 nsMathMLmtdInnerFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle)
 {
   nsBlockFrame::DidSetComputedStyle(aOldComputedStyle);
-  mUniqueStyleText->Destroy(PresContext());
-  mUniqueStyleText = new (PresContext()) nsStyleText(*StyleText());
+  mUniqueStyleText = MakeUnique<nsStyleText>(*StyleText());
 }
--- a/layout/mathml/nsMathMLmtableFrame.h
+++ b/layout/mathml/nsMathMLmtableFrame.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsMathMLmtableFrame_h___
 #define nsMathMLmtableFrame_h___
 
 #include "mozilla/Attributes.h"
+#include "mozilla/UniquePtr.h"
 #include "nsMathMLContainerFrame.h"
 #include "nsBlockFrame.h"
 #include "nsTableWrapperFrame.h"
 #include "nsTableRowFrame.h"
 #include "nsTableCellFrame.h"
 
 //
 // <mtable> -- table or matrix
@@ -332,15 +333,15 @@ public:
   {
     return mFrames.FirstChild() !=
            mFrames.LastChild() ||
            !mFrames.FirstChild();
   }
 
 protected:
   explicit nsMathMLmtdInnerFrame(ComputedStyle* aStyle);
-  virtual ~nsMathMLmtdInnerFrame();
+  virtual ~nsMathMLmtdInnerFrame() {}
 
-  nsStyleText* mUniqueStyleText;
+  mozilla::UniquePtr<nsStyleText> mUniqueStyleText;
 
 };  // class nsMathMLmtdInnerFrame
 
 #endif /* nsMathMLmtableFrame_h___ */