Bug 1340958 - Allocate StyleRule only if we need to compose styles. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 17 Mar 2017 12:48:51 +0900
changeset 500840 efc0e046a5c1155096a5c1343a85b3765a9815a4
parent 500839 d94b4a1a9c226ba649f02eb72daf3285ea8e91f2
child 500841 f2fdcee9cb8fce2728e7f7e1c057caaf00fcb40c
push id49816
push userbmo:tchiovoloni@mozilla.com
push dateFri, 17 Mar 2017 20:44:02 +0000
reviewersbirtles
bugs1340958
milestone55.0a1
Bug 1340958 - Allocate StyleRule only if we need to compose styles. r=birtles MozReview-Commit-ID: 6ucsxBAaYRp
dom/animation/KeyframeEffectReadOnly.cpp
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -435,17 +435,17 @@ KeyframeEffectReadOnly::ResolveBaseStyle
 
 StyleAnimationValue
 KeyframeEffectReadOnly::GetUnderlyingStyle(
   nsCSSPropertyID aProperty,
   const RefPtr<AnimValuesStyleRule>& aAnimationRule)
 {
   StyleAnimationValue result;
 
-  if (aAnimationRule->HasValue(aProperty)) {
+  if (aAnimationRule && aAnimationRule->HasValue(aProperty)) {
     // If we have already composed style for the property, we use the style
     // as the underlying style.
     DebugOnly<bool> success = aAnimationRule->GetValue(aProperty, result);
     MOZ_ASSERT(success, "AnimValuesStyleRule::GetValue should not fail");
   } else {
     // If we are composing with composite operation that is not 'replace'
     // and we have not composed style for the property yet, we have to get
     // the base style for the property.
@@ -618,33 +618,33 @@ KeyframeEffectReadOnly::ComposeStyle(
       } else if (valuePosition < 0.5) {
         aStyleRule.mServo->AddValue(prop.mProperty, servoFromValue);
       } else {
         aStyleRule.mServo->AddValue(prop.mProperty, servoToValue);
       }
     } else {
       // Gecko backend
 
-      if (!aStyleRule.mGecko) {
-        // Allocate the style rule now that we know we have animation data.
-        aStyleRule.mGecko = new AnimValuesStyleRule();
-      }
-
       StyleAnimationValue fromValue =
         CompositeValue(prop.mProperty, aStyleRule.mGecko,
                        segment->mFromValue.mGecko,
                        segment->mFromComposite);
       StyleAnimationValue toValue =
         CompositeValue(prop.mProperty, aStyleRule.mGecko,
                        segment->mToValue.mGecko,
                        segment->mToComposite);
       if (fromValue.IsNull() || toValue.IsNull()) {
         continue;
       }
 
+      if (!aStyleRule.mGecko) {
+        // Allocate the style rule now that we know we have animation data.
+        aStyleRule.mGecko = new AnimValuesStyleRule();
+      }
+
       // Iteration composition for accumulate
       if (mEffectOptions.mIterationComposite ==
           IterationCompositeOperation::Accumulate &&
           computedTiming.mCurrentIteration > 0) {
         const AnimationPropertySegment& lastSegment =
           prop.mSegments.LastElement();
         // FIXME: Bug 1293492: Add a utility function to calculate both of
         // below StyleAnimationValues.