Bug 1321022 pt 6: Use UniquePtr instead of nsAutoPtr (& nsCSSValue setters) in font-variations-setting StyleAnimationValue code. r=jfkthame
authorDaniel Holbert <dholbert@cs.stanford.edu>
Sat, 03 Dec 2016 12:18:43 +0000
changeset 325217 870d19bb47592adec25736d9e7260bb0ca917fc0
parent 325216 7878d113285818e7a5ec92e4c43cd43a84728db3
child 325218 71fff6495d23e355d5147d9673dfd5df30d3953c
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjfkthame
bugs1321022
milestone53.0a1
Bug 1321022 pt 6: Use UniquePtr instead of nsAutoPtr (& nsCSSValue setters) in font-variations-setting StyleAnimationValue code. r=jfkthame MozReview-Commit-ID: CSj2wcZlTJs
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -1918,16 +1918,32 @@ AppendToCSSValueList(UniquePtr<nsCSSValu
   if (!aHead) {
     aHead = Move(aValueToAppend);
     *aTail = aHead.get();
   } else {
     (*aTail) = (*aTail)->mNext = aValueToAppend.release();
   }
 }
 
+void
+AppendToCSSValuePairList(UniquePtr<nsCSSValuePairList>& aHead,
+                         UniquePtr<nsCSSValuePairList>&& aValueToAppend,
+                         nsCSSValuePairList** aTail)
+{
+  MOZ_ASSERT(!aHead == !*aTail,
+             "Can't have head w/o tail, & vice versa");
+
+  if (!aHead) {
+    aHead = Move(aValueToAppend);
+    *aTail = aHead.get();
+  } else {
+    (*aTail) = (*aTail)->mNext = aValueToAppend.release();
+  }
+}
+
 static UniquePtr<nsCSSValueList>
 AddWeightedShadowItems(double aCoeff1, const nsCSSValue &aValue1,
                        double aCoeff2, const nsCSSValue &aValue2,
                        ColorAdditionType aColorAdditionType)
 {
   // X, Y, Radius, Spread, Color, Inset
   MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Array,
              "wrong unit");
@@ -4500,39 +4516,37 @@ StyleAnimationValue::ExtractComputedValu
           }
 
           aComputedValue.SetTransformValue(
               new nsCSSValueSharedList(result.forget()));
           break;
         }
 
         case eCSSProperty_font_variation_settings: {
-          const nsStyleFont *font =
-            static_cast<const nsStyleFont*>(styleStruct);
-          nsAutoPtr<nsCSSValuePairList> result;
+          auto font = static_cast<const nsStyleFont*>(styleStruct);
+          UniquePtr<nsCSSValuePairList> result;
           if (!font->mFont.fontVariationSettings.IsEmpty()) {
             // Make a new list that clones the current settings
-            nsCSSValuePairList **resultTail = getter_Transfers(result);
+            nsCSSValuePairList* tail = nullptr;
             for (auto v : font->mFont.fontVariationSettings) {
-              nsCSSValuePairList *clone = new nsCSSValuePairList;
+              auto clone = MakeUnique<nsCSSValuePairList>();
               // OpenType font tags are stored in nsFont as 32-bit unsigned
               // values, but represented in CSS as 4-character ASCII strings,
               // beginning with the high byte of the value. So to clone the
               // tag here, we append each of its 4 bytes to a string.
               nsAutoString tagString;
               tagString.Append(char(v.mTag >> 24));
               tagString.Append(char(v.mTag >> 16));
               tagString.Append(char(v.mTag >> 8));
               tagString.Append(char(v.mTag));
-              clone->mXValue = nsCSSValue(tagString, eCSSUnit_String);
-              clone->mYValue = nsCSSValue(v.mValue, eCSSUnit_Number);
-              *resultTail = clone;
-              resultTail = &clone->mNext;
+              clone->mXValue.SetStringValue(tagString, eCSSUnit_String);
+              clone->mYValue.SetFloatValue(v.mValue, eCSSUnit_Number);
+              AppendToCSSValuePairList(result, Move(clone), &tail);
             }
-            aComputedValue.SetAndAdoptCSSValuePairListValue(result.forget());
+            aComputedValue.SetAndAdoptCSSValuePairListValue(result.release());
           } else {
             aComputedValue.SetNormalValue();
           }
           break;
         }
 
         default:
           MOZ_ASSERT(false, "missing property implementation");