Bug 1340958 - Allocate StyleRule only if we need to compose styles. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 17 Mar 2017 12:48:51 +0900
changeset 500409 9fbdebbd6b645a5d9a5e11e6111d59704e74c8ad
parent 500408 132125b8f31b51ddb90188b7af686d92f29ebc7c
child 500410 e831c88ec75c2cbd2d41ad305a541333e15342ab
push id49724
push userhikezoe@mozilla.com
push dateFri, 17 Mar 2017 06:26:10 +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.