Bug 1264787: Make nsCSSValue's AdoptListValue & AdoptPairListValue methods take a UniquePtr. r=heycam
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 20 Apr 2016 10:37:06 -0700
changeset 331999 8bc1d52fcf71015e32838b9c933971807069f3b1
parent 331998 e0d5bf97a1821bd08b45415bc701b3e7c56bd0a4
child 332000 22d82e970d2ad09e8b8f73deef2a258c8b4b42f6
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1264787
milestone48.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 1264787: Make nsCSSValue's AdoptListValue & AdoptPairListValue methods take a UniquePtr. r=heycam MozReview-Commit-ID: 94aYEtySHsW
layout/style/StyleAnimationValue.cpp
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -1966,17 +1966,17 @@ AddShapeFunction(nsCSSProperty aProperty
 
       const nsCSSValuePairList* points1 = func1->Item(2).GetPairListValue();
       const nsCSSValuePairList* points2 = func2->Item(2).GetPairListValue();
       UniquePtr<nsCSSValuePairList> resultPoints =
         AddCSSValuePairList(aProperty, aCoeff1, points1, aCoeff2, points2);
       if (!resultPoints) {
         return nullptr;
       }
-      resultFuncArgs->Item(2).AdoptPairListValue(resultPoints.release());
+      resultFuncArgs->Item(2).AdoptPairListValue(Move(resultPoints));
       break;
     }
     case eCSSKeyword_inset: {
       MOZ_ASSERT(func1->Count() == 6 && func2->Count() == 6,
                  "Update for CSSParserImpl::ParseInsetFunction changes");
       // Items 1-4 are respectively the top, right, bottom and left offsets
       // from the reference box.
       for (size_t i = 1; i <= 4; ++i) {
@@ -3091,28 +3091,28 @@ StyleAnimationValue::UncomputeValue(nsCS
     case eUnit_Dasharray:
     case eUnit_Shadow:
     case eUnit_Filter:
     case eUnit_BackgroundPosition:
       {
         UniquePtr<nsCSSValueList> computedList =
           aComputedValue.TakeCSSValueListValue();
         if (computedList) {
-          aSpecifiedValue.AdoptListValue(computedList.release());
+          aSpecifiedValue.AdoptListValue(Move(computedList));
         } else {
           aSpecifiedValue.SetNoneValue();
         }
       }
       break;
     case eUnit_CSSValuePairList:
       {
         UniquePtr<nsCSSValuePairList> computedList =
           aComputedValue.TakeCSSValuePairListValue();
         MOZ_ASSERT(computedList, "Pair list should never be null");
-        aSpecifiedValue.AdoptPairListValue(computedList.release());
+        aSpecifiedValue.AdoptPairListValue(Move(computedList));
       }
       break;
     default:
       return UncomputeValue(aProperty, aComputedValue, aSpecifiedValue);
   }
   return true;
 }
 
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -617,28 +617,27 @@ void nsCSSValue::SetDependentListValue(n
   Reset();
   if (aList) {
     mUnit = eCSSUnit_ListDep;
     mValue.mListDependent = aList;
   }
 }
 
 void
-nsCSSValue::AdoptListValue(nsCSSValueList*&& aValue)
+nsCSSValue::AdoptListValue(UniquePtr<nsCSSValueList> aValue)
 {
   // We have to copy the first element since for owned lists the first
   // element should be an nsCSSValueList_heap object.
   SetListValue();
   // FIXME: If nsCSSValue gets a swap method or move assignment operator,
   // we should use that here to avoid allocating an extra value.
   mValue.mList->mValue = aValue->mValue;
   mValue.mList->mNext  = aValue->mNext;
   aValue->mNext = nullptr;
-  delete aValue;
-  aValue = nullptr;
+  aValue.reset();
 }
 
 nsCSSValuePairList* nsCSSValue::SetPairListValue()
 {
   Reset();
   mUnit = eCSSUnit_PairList;
   mValue.mPairList = new nsCSSValuePairList_heap;
   mValue.mPairList->AddRef();
@@ -650,29 +649,28 @@ void nsCSSValue::SetDependentPairListVal
   Reset();
   if (aList) {
     mUnit = eCSSUnit_PairListDep;
     mValue.mPairListDependent = aList;
   }
 }
 
 void
-nsCSSValue::AdoptPairListValue(nsCSSValuePairList*&& aValue)
+nsCSSValue::AdoptPairListValue(UniquePtr<nsCSSValuePairList> aValue)
 {
-  // We have to copy the first element since for owned pair lists the first
+  // We have to copy the first element, since for owned pair lists, the first
   // element should be an nsCSSValuePairList_heap object.
   SetPairListValue();
   // FIXME: If nsCSSValue gets a swap method or move assignment operator,
   // we should use that here to avoid allocating extra values.
   mValue.mPairList->mXValue = aValue->mXValue;
   mValue.mPairList->mYValue = aValue->mYValue;
   mValue.mPairList->mNext   = aValue->mNext;
   aValue->mNext = nullptr;
-  delete aValue;
-  aValue = nullptr;
+  aValue.reset();
 }
 
 void nsCSSValue::SetAutoValue()
 {
   Reset();
   mUnit = eCSSUnit_Auto;
 }
 
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -6,16 +6,17 @@
 /* representation of simple property values within CSS declarations */
 
 #ifndef nsCSSValue_h___
 #define nsCSSValue_h___
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/SheetType.h"
+#include "mozilla/UniquePtr.h"
 
 #include "nsIPrincipal.h"
 #include "nsIURI.h"
 #include "nsCOMPtr.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSProperty.h"
 #include "nsColor.h"
 #include "nsCoord.h"
@@ -714,18 +715,18 @@ public:
 
   // These are a little different - they allocate storage for you and
   // return a handle.
   nsCSSRect& SetRectValue();
   nsCSSValueList* SetListValue();
   nsCSSValuePairList* SetPairListValue();
 
   // These take ownership of the passed-in resource.
-  void AdoptListValue(nsCSSValueList*&& aValue);
-  void AdoptPairListValue(nsCSSValuePairList*&& aValue);
+  void AdoptListValue(mozilla::UniquePtr<nsCSSValueList> aValue);
+  void AdoptPairListValue(mozilla::UniquePtr<nsCSSValuePairList> aValue);
 
   void StartImageLoad(nsIDocument* aDocument) const;  // Only pretend const
 
   // Initializes as a function value with the specified function id.
   Array* InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs);
   // Checks if this is a function value with the specified function id.
   bool EqualsFunction(nsCSSKeyword aFunctionId) const;