Bug 1304540 part 2: Use nsCOMPtr/RefPtr (and their forget() API) instead of manual NS_ADDREF macros, in a few files within layout. r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 21 Sep 2016 15:41:26 -0700
changeset 360015 058cf01f6cf2d2526c28b864a78afd4b97189b2a
parent 360014 5fd3903b907579e41b9528e95ca403044da18d6b
child 360016 64fd93d6dbf216b5f85e89d0b6d6b4bfe9b68cc7
push id1369
push userjlorenzo@mozilla.com
push dateMon, 27 Feb 2017 14:59:41 +0000
treeherdermozilla-release@d75a1dba431f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1304540
milestone52.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 1304540 part 2: Use nsCOMPtr/RefPtr (and their forget() API) instead of manual NS_ADDREF macros, in a few files within layout. r=mats MozReview-Commit-ID: SrJNtbwc1B
layout/base/nsFrameTraversal.cpp
layout/base/nsPresShell.cpp
layout/base/nsRefreshDriver.cpp
layout/build/nsContentDLF.cpp
layout/generic/nsTextFrame.cpp
--- a/layout/base/nsFrameTraversal.cpp
+++ b/layout/base/nsFrameTraversal.cpp
@@ -120,19 +120,17 @@ protected:
 /************IMPLEMENTATIONS**************/
 
 nsresult
 NS_CreateFrameTraversal(nsIFrameTraversal** aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
   nsCOMPtr<nsIFrameTraversal> t = new nsFrameTraversal();
-
-  *aResult = t;
-  NS_ADDREF(*aResult);
+  t.forget(aResult);
 
   return NS_OK;
 }
 
 nsresult
 NS_NewFrameTraversal(nsIFrameEnumerator **aEnumerator,
                      nsPresContext* aPresContext,
                      nsIFrame *aStart,
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1507,25 +1507,24 @@ PresShell::GetDisplaySelection(int16_t *
 
 NS_IMETHODIMP
 PresShell::GetSelection(RawSelectionType aRawSelectionType,
                         nsISelection **aSelection)
 {
   if (!aSelection || !mSelection)
     return NS_ERROR_NULL_POINTER;
 
-  *aSelection =
+  nsCOMPtr<nsISelection> selection =
     mSelection->GetSelection(ToSelectionType(aRawSelectionType));
 
-  if (!(*aSelection)) {
+  if (!selection) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  NS_ADDREF(*aSelection);
-
+  selection.forget(aSelection);
   return NS_OK;
 }
 
 Selection*
 PresShell::GetCurrentSelection(SelectionType aSelectionType)
 {
   if (!mSelection)
     return nullptr;
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -1732,31 +1732,29 @@ nsRefreshDriver::Tick(int64_t aNowEpoch,
             continue;
 
           if (!tracingStyleFlush) {
             tracingStyleFlush = true;
             profiler_tracing("Paint", "Styles", mStyleCause, TRACING_INTERVAL_START);
             mStyleCause = nullptr;
           }
 
-          NS_ADDREF(shell);
+          nsCOMPtr<nsIPresShell> shellKungFuDeathGrip(shell);
           mStyleFlushObservers.RemoveElement(shell);
           RestyleManagerHandle restyleManager =
             shell->GetPresContext()->RestyleManager();
           restyleManager->SetObservingRefreshDriver(false);
           shell->FlushPendingNotifications(ChangesToFlush(Flush_Style, false));
           // Inform the FontFaceSet that we ticked, so that it can resolve its
           // ready promise if it needs to (though it might still be waiting on
           // a layout flush).
           nsPresContext* presContext = shell->GetPresContext();
           if (presContext) {
             presContext->NotifyFontFaceSetOnRefresh();
           }
-          NS_RELEASE(shell);
-
           mNeedToRecomputeVisibility = true;
         }
 
 
         if (tracingStyleFlush) {
           profiler_tracing("Paint", "Styles", TRACING_INTERVAL_END);
         }
       }
@@ -1774,32 +1772,30 @@ nsRefreshDriver::Tick(int64_t aNowEpoch,
           continue;
 
         if (!tracingLayoutFlush) {
           tracingLayoutFlush = true;
           profiler_tracing("Paint", "Reflow", mReflowCause, TRACING_INTERVAL_START);
           mReflowCause = nullptr;
         }
 
-        NS_ADDREF(shell);
+        nsCOMPtr<nsIPresShell> shellKungFuDeathGrip(shell);
         mLayoutFlushObservers.RemoveElement(shell);
         shell->mReflowScheduled = false;
         shell->mSuppressInterruptibleReflows = false;
         mozFlushType flushType = HasPendingAnimations(shell)
                                ? Flush_Layout
                                : Flush_InterruptibleLayout;
         shell->FlushPendingNotifications(ChangesToFlush(flushType, false));
         // Inform the FontFaceSet that we ticked, so that it can resolve its
         // ready promise if it needs to.
         nsPresContext* presContext = shell->GetPresContext();
         if (presContext) {
           presContext->NotifyFontFaceSetOnRefresh();
         }
-        NS_RELEASE(shell);
-
         mNeedToRecomputeVisibility = true;
       }
 
       if (tracingLayoutFlush) {
         profiler_tracing("Paint", "Reflow", TRACING_INTERVAL_END);
       }
     }
 
--- a/layout/build/nsContentDLF.cpp
+++ b/layout/build/nsContentDLF.cpp
@@ -324,18 +324,17 @@ nsContentDLF::CreateBlankDocument(nsILoa
     }
   }
 
   // add a nice bow
   if (NS_SUCCEEDED(rv)) {
     blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
     blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
     
-    *aDocument = blankDoc;
-    NS_ADDREF(*aDocument);
+    blankDoc.forget(aDocument);
   }
   return rv;
 }
 
 
 nsresult
 nsContentDLF::CreateDocument(const char* aCommand,
                              nsIChannel* aChannel,
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -1908,18 +1908,17 @@ GetFontGroupForFrame(nsIFrame* aFrame, f
                      nsFontMetrics** aOutFontMetrics = nullptr)
 {
   RefPtr<nsFontMetrics> metrics =
     nsLayoutUtils::GetFontMetricsForFrame(aFrame, aFontSizeInflation);
   gfxFontGroup* fontGroup = metrics->GetThebesFontGroup();
 
   // Populate outparam before we return:
   if (aOutFontMetrics) {
-    *aOutFontMetrics = metrics;
-    NS_ADDREF(*aOutFontMetrics);
+    metrics.forget(aOutFontMetrics);
   }
   // XXX this is a bit bogus, we're releasing 'metrics' so the
   // returned font-group might actually be torn down, although because
   // of the way the device context caches font metrics, this seems to
   // not actually happen. But we should fix this.
   return fontGroup;
 }