Bug 1216843 - Part 8: Make AddShadowItems() return UniquePtr and rename it to AddWeightedShadowItems(). r=dholbert
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 13 Sep 2016 11:48:45 +0900
changeset 354925 9900b2f32860efbf5d4f6c9df1bb37e0e403e090
parent 354924 8bef6bb7442c95e31ebe6217a15698c8c2f820ec
child 354926 ce1f420b495f2b559fd2a7d1b0501c6d93d5bc23
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1216843
milestone51.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 1216843 - Part 8: Make AddShadowItems() return UniquePtr and rename it to AddWeightedShadowItems(). r=dholbert MozReview-Commit-ID: 2Sok2MngunC
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -1273,20 +1273,35 @@ DiluteColor(const nsCSSValue& aValue, do
   double factor = 1.0 / Aresf;
   aResult.SetColorValue(
     NS_RGBA(ClampColor(R * aDilutionRatio * factor),
             ClampColor(G * aDilutionRatio * factor),
             ClampColor(B * aDilutionRatio * factor),
             NSToIntRound(Aresf * 255.0)));
 }
 
-static bool
-AddShadowItems(double aCoeff1, const nsCSSValue &aValue1,
-               double aCoeff2, const nsCSSValue &aValue2,
-               nsCSSValueList **&aResultTail)
+void
+AppendToCSSValueList(UniquePtr<nsCSSValueList>& aHead,
+                     UniquePtr<nsCSSValueList>&& aValueToAppend,
+                     nsCSSValueList** 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)
 {
   // X, Y, Radius, Spread, Color, Inset
   MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Array,
              "wrong unit");
   MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Array,
              "wrong unit");
   nsCSSValue::Array *array1 = aValue1.GetArrayValue();
   nsCSSValue::Array *array2 = aValue2.GetArrayValue();
@@ -1305,37 +1320,35 @@ AddShadowItems(double aCoeff1, const nsC
   const nsCSSValue& inset2 = array2->Item(5);
   if ((color1.GetUnit() != color2.GetUnit() &&
        (!color1.IsNumericColorUnit() || !color2.IsNumericColorUnit())) ||
       inset1.GetUnit() != inset2.GetUnit()) {
     // We don't know how to animate between color and no-color, or
     // between inset and not-inset.
     // NOTE: In case when both colors' units are eCSSUnit_Null, that means
     // neither color value was specified, so we can interpolate.
-    return false;
+    return nullptr;
   }
 
   if (color1.GetUnit() != eCSSUnit_Null) {
     if (aCoeff2 == 0.0 && aCoeff1 != 1.0) {
       DiluteColor(color1, aCoeff1, resultArray->Item(4));
     } else {
       AddWeightedColors(aCoeff1, color1, aCoeff2, color2,
                         ColorAdditionType::Clamped,
                         resultArray->Item(4));
     }
   }
 
   MOZ_ASSERT(inset1 == inset2, "should match");
   resultArray->Item(5) = inset1;
 
-  nsCSSValueList *resultItem = new nsCSSValueList;
+  auto resultItem = MakeUnique<nsCSSValueList>();
   resultItem->mValue.SetArrayValue(resultArray, eCSSUnit_Array);
-  *aResultTail = resultItem;
-  aResultTail = &resultItem->mNext;
-  return true;
+  return resultItem;
 }
 
 static void
 AddTransformTranslate(double aCoeff1, const nsCSSValue &aValue1,
                       double aCoeff2, const nsCSSValue &aValue2,
                       nsCSSValue &aResult)
 {
   MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Percent ||
@@ -1854,28 +1867,26 @@ AddFilterFunctionImpl(double aCoeff1, co
                                initialVal);
       break;
     case eCSSKeyword_hue_rotate:
       AddCSSValueAngle(aCoeff1, funcArg1,
                        aCoeff2, funcArg2,
                        resultArg);
       break;
     case eCSSKeyword_drop_shadow: {
-      nsCSSValueList* resultShadow = resultArg.SetListValue();
-      nsAutoPtr<nsCSSValueList> shadowValue;
-      nsCSSValueList **shadowTail = getter_Transfers(shadowValue);
       MOZ_ASSERT(!funcArg1.GetListValue()->mNext &&
                  !funcArg2.GetListValue()->mNext,
                  "drop-shadow filter func doesn't support lists");
-      if (!AddShadowItems(aCoeff1, funcArg1.GetListValue()->mValue,
-                          aCoeff2, funcArg2.GetListValue()->mValue,
-                          shadowTail)) {
+      UniquePtr<nsCSSValueList> shadowValue =
+        AddWeightedShadowItems(aCoeff1, funcArg1.GetListValue()->mValue,
+                               aCoeff2, funcArg2.GetListValue()->mValue);
+      if (!shadowValue) {
         return false;
       }
-      *resultShadow = *shadowValue;
+      resultArg.AdoptListValue(Move(shadowValue));
       break;
     }
     default:
       MOZ_ASSERT(false, "unknown filter function");
       return false;
   }
 
   *aResultTail = resultListEntry.forget();
@@ -2660,52 +2671,56 @@ StyleAnimationValue::AddWeighted(nsCSSPr
     }
     case eUnit_Shadow: {
       // This is implemented according to:
       // http://dev.w3.org/csswg/css3-transitions/#animation-of-property-types-
       // and the third item in the summary of:
       // http://lists.w3.org/Archives/Public/www-style/2009Jul/0050.html
       const nsCSSValueList *shadow1 = aValue1.GetCSSValueListValue();
       const nsCSSValueList *shadow2 = aValue2.GetCSSValueListValue();
-      nsAutoPtr<nsCSSValueList> result;
-      nsCSSValueList **resultTail = getter_Transfers(result);
+      UniquePtr<nsCSSValueList> result;
+      nsCSSValueList* tail = nullptr;
       while (shadow1 && shadow2) {
-        if (!AddShadowItems(aCoeff1, shadow1->mValue,
-                            aCoeff2, shadow2->mValue,
-                            resultTail)) {
+        UniquePtr<nsCSSValueList> shadowValue =
+          AddWeightedShadowItems(aCoeff1, shadow1->mValue,
+                                 aCoeff2, shadow2->mValue);
+        if (!shadowValue) {
           return false;
         }
         shadow1 = shadow1->mNext;
         shadow2 = shadow2->mNext;
+        AppendToCSSValueList(result, Move(shadowValue), &tail);
       }
       if (shadow1 || shadow2) {
         const nsCSSValueList *longShadow;
         double longCoeff;
         if (shadow1) {
           longShadow = shadow1;
           longCoeff = aCoeff1;
         } else {
           longShadow = shadow2;
           longCoeff = aCoeff2;
         }
 
         while (longShadow) {
           // Passing coefficients that add to less than 1 produces the
           // desired result of interpolating "0 0 0 transparent" with
           // the current shadow.
-          if (!AddShadowItems(longCoeff, longShadow->mValue,
-                              0.0, longShadow->mValue,
-                              resultTail)) {
+          UniquePtr<nsCSSValueList> shadowValue =
+            AddWeightedShadowItems(longCoeff, longShadow->mValue,
+                                   0.0, longShadow->mValue);
+          if (!shadowValue) {
             return false;
           }
 
           longShadow = longShadow->mNext;
+          AppendToCSSValueList(result, Move(shadowValue), &tail);
         }
       }
-      aResultValue.SetAndAdoptCSSValueListValue(result.forget(), eUnit_Shadow);
+      aResultValue.SetAndAdoptCSSValueListValue(result.release(), eUnit_Shadow);
       return true;
     }
     case eUnit_Shape: {
       RefPtr<nsCSSValue::Array> result =
         AddShapeFunction(aProperty,
                          aCoeff1, aValue1.GetCSSValueArrayValue(),
                          aCoeff2, aValue2.GetCSSValueArrayValue());
       if (!result) {