Bug 1454040 - part 1 - make time intervals in nsSMILTimedElement UniquePtrs; r=dholbert
authorNathan Froyd <froydnj@mozilla.com>
Mon, 16 Apr 2018 11:15:56 -0400
changeset 467389 20babe43b5d5723b41cba1fbcd6313ed229fcf04
parent 467388 61fd0798f0a8ee4c38dc1cc9f1cdb34d3bf64b2b
child 467390 33c879d73a091e703187ea8ac0e7a0dcc1e0ea11
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1454040
milestone61.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 1454040 - part 1 - make time intervals in nsSMILTimedElement UniquePtrs; r=dholbert UniquePtr is nicer than nsAutoPtr.
dom/smil/nsSMILTimedElement.cpp
dom/smil/nsSMILTimedElement.h
--- a/dom/smil/nsSMILTimedElement.cpp
+++ b/dom/smil/nsSMILTimedElement.cpp
@@ -625,17 +625,17 @@ nsSMILTimedElement::DoSampleAt(nsSMILTim
     case STATE_STARTUP:
       {
         nsSMILInterval firstInterval;
         mElementState = GetNextInterval(nullptr, nullptr, nullptr, firstInterval)
          ? STATE_WAITING
          : STATE_POSTACTIVE;
         stateChanged = true;
         if (mElementState == STATE_WAITING) {
-          mCurrentInterval = new nsSMILInterval(firstInterval);
+          mCurrentInterval = MakeUnique<nsSMILInterval>(firstInterval);
           NotifyNewInterval();
         }
       }
       break;
 
     case STATE_WAITING:
       {
         if (mCurrentInterval->Begin()->Time() <= sampleTime) {
@@ -668,36 +668,36 @@ nsSMILTimedElement::DoSampleAt(nsSMILTim
         // Ending early will change the interval but we don't notify dependents
         // of the change until we have closed off the current interval (since we
         // don't want dependencies to un-end our early end).
         bool didApplyEarlyEnd = ApplyEarlyEnd(sampleTime);
 
         if (mCurrentInterval->End()->Time() <= sampleTime) {
           nsSMILInterval newInterval;
           mElementState =
-            GetNextInterval(mCurrentInterval, nullptr, nullptr, newInterval)
+            GetNextInterval(mCurrentInterval.get(), nullptr, nullptr, newInterval)
             ? STATE_WAITING
             : STATE_POSTACTIVE;
           if (mClient) {
             mClient->Inactivate(mFillMode == FILL_FREEZE);
           }
           mCurrentInterval->FixEnd();
           if (mSeekState == SEEK_NOT_SEEKING) {
             FireTimeEventAsync(eSMILEndEvent, 0);
           }
           mCurrentRepeatIteration = 0;
-          mOldIntervals.AppendElement(mCurrentInterval.forget());
+          mOldIntervals.AppendElement(Move(mCurrentInterval));
           SampleFillValue();
           if (mElementState == STATE_WAITING) {
-            mCurrentInterval = new nsSMILInterval(newInterval);
+            mCurrentInterval = MakeUnique<nsSMILInterval>(newInterval);
           }
           // We are now in a consistent state to dispatch notifications
           if (didApplyEarlyEnd) {
             NotifyChangedInterval(
-                mOldIntervals[mOldIntervals.Length() - 1], false, true);
+                mOldIntervals[mOldIntervals.Length() - 1].get(), false, true);
           }
           if (mElementState == STATE_WAITING) {
             NotifyNewInterval();
           }
           FilterHistory();
           stateChanged = true;
         } else if (mCurrentInterval->Begin()->Time() <= sampleTime) {
           MOZ_ASSERT(!didApplyEarlyEnd,
@@ -763,17 +763,17 @@ void
 nsSMILTimedElement::HandleContainerTimeChange()
 {
   // In future we could possibly introduce a separate change notice for time
   // container changes and only notify those dependents who live in other time
   // containers. For now we don't bother because when we re-resolve the time in
   // the nsSMILTimeValueSpec we'll check if anything has changed and if not, we
   // won't go any further.
   if (mElementState == STATE_WAITING || mElementState == STATE_ACTIVE) {
-    NotifyChangedInterval(mCurrentInterval, false, false);
+    NotifyChangedInterval(mCurrentInterval.get(), false, false);
   }
 }
 
 namespace
 {
   bool
   RemoveNonDynamic(nsSMILInstanceTime* aInstanceTime)
   {
@@ -1608,17 +1608,17 @@ nsSMILTimedElement::FilterIntervals()
   for (uint32_t i = 0; i < mOldIntervals.Length(); ++i)
   {
     nsSMILInterval* interval = mOldIntervals[i].get();
     if (i != 0 && /*skip first interval*/
         i + 1 < mOldIntervals.Length() && /*skip previous interval*/
         (i < threshold || !interval->IsDependencyChainLink())) {
       interval->Unlink(true /*filtered, not deleted*/);
     } else {
-      filteredList.AppendElement(mOldIntervals[i].forget());
+      filteredList.AppendElement(Move(mOldIntervals[i]));
     }
   }
   mOldIntervals.Clear();
   mOldIntervals.SwapElements(filteredList);
 }
 
 namespace
 {
@@ -2084,24 +2084,24 @@ nsSMILTimedElement::UpdateCurrentInterva
     return;
   }
 
   // If the interval is active the begin time is fixed.
   const nsSMILInstanceTime* beginTime = mElementState == STATE_ACTIVE
                                       ? mCurrentInterval->Begin()
                                       : nullptr;
   nsSMILInterval updatedInterval;
-  if (GetNextInterval(GetPreviousInterval(), mCurrentInterval,
+  if (GetNextInterval(GetPreviousInterval(), mCurrentInterval.get(),
                       beginTime, updatedInterval)) {
 
     if (mElementState == STATE_POSTACTIVE) {
 
       MOZ_ASSERT(!mCurrentInterval,
                  "In postactive state but the interval has been set");
-      mCurrentInterval = new nsSMILInterval(updatedInterval);
+      mCurrentInterval = MakeUnique<nsSMILInterval>(updatedInterval);
       mElementState = STATE_WAITING;
       NotifyNewInterval();
 
     } else {
 
       bool beginChanged = false;
       bool endChanged   = false;
 
@@ -2113,31 +2113,31 @@ nsSMILTimedElement::UpdateCurrentInterva
       }
 
       if (!updatedInterval.End()->SameTimeAndBase(*mCurrentInterval->End())) {
         mCurrentInterval->SetEnd(*updatedInterval.End());
         endChanged = true;
       }
 
       if (beginChanged || endChanged || aForceChangeNotice) {
-        NotifyChangedInterval(mCurrentInterval, beginChanged, endChanged);
+        NotifyChangedInterval(mCurrentInterval.get(), beginChanged, endChanged);
       }
     }
 
     // There's a chance our next milestone has now changed, so update the time
     // container
     RegisterMilestone();
   } else { // GetNextInterval failed: Current interval is no longer valid
     if (mElementState == STATE_ACTIVE) {
       // The interval is active so we can't just delete it, instead trim it so
       // that begin==end.
       if (!mCurrentInterval->End()->SameTimeAndBase(*mCurrentInterval->Begin()))
       {
         mCurrentInterval->SetEnd(*mCurrentInterval->Begin());
-        NotifyChangedInterval(mCurrentInterval, false, true);
+        NotifyChangedInterval(mCurrentInterval.get(), false, true);
       }
       // The transition to the postactive state will take place on the next
       // sample (along with firing end events, clearing intervals etc.)
       RegisterMilestone();
     } else if (mElementState == STATE_WAITING) {
       AutoRestore<uint8_t> deleteCountRestorer(mDeleteCount);
       ++mDeleteCount;
       mElementState = STATE_POSTACTIVE;
@@ -2335,17 +2335,17 @@ nsSMILTimedElement::NotifyNewInterval()
              "interval is not set");
 
   nsSMILTimeContainer* container = GetTimeContainer();
   if (container) {
     container->SyncPauseTime();
   }
 
   for (auto iter = mTimeDependents.Iter(); !iter.Done(); iter.Next()) {
-    nsSMILInterval* interval = mCurrentInterval;
+    nsSMILInterval* interval = mCurrentInterval.get();
     // It's possible that in notifying one new time dependent of a new interval
     // that a chain reaction is triggered which results in the original
     // interval disappearing. If that's the case we can skip sending further
     // notifications.
     if (!interval) {
       break;
     }
     nsSMILTimeValueSpec* spec = iter.Get()->GetKey();
--- a/dom/smil/nsSMILTimedElement.h
+++ b/dom/smil/nsSMILTimedElement.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NS_SMILTIMEDELEMENT_H_
 #define NS_SMILTIMEDELEMENT_H_
 
 #include "mozilla/EventForwards.h"
 #include "mozilla/Move.h"
+#include "mozilla/UniquePtr.h"
 #include "nsSMILInterval.h"
 #include "nsSMILInstanceTime.h"
 #include "nsSMILMilestone.h"
 #include "nsSMILTimeValueSpec.h"
 #include "nsSMILRepeatCount.h"
 #include "nsSMILTypes.h"
 #include "nsTArray.h"
 #include "nsTHashtable.h"
@@ -349,17 +350,17 @@ public:
   void Unlink();
 
   typedef bool (*RemovalTestFunction)(nsSMILInstanceTime* aInstance);
 
 protected:
   // Typedefs
   typedef nsTArray<nsAutoPtr<nsSMILTimeValueSpec> > TimeValueSpecList;
   typedef nsTArray<RefPtr<nsSMILInstanceTime> >   InstanceTimeList;
-  typedef nsTArray<nsAutoPtr<nsSMILInterval> >      IntervalList;
+  typedef nsTArray<mozilla::UniquePtr<nsSMILInterval>> IntervalList;
   typedef nsPtrHashKey<nsSMILTimeValueSpec> TimeValueSpecPtrKey;
   typedef nsTHashtable<TimeValueSpecPtrKey> TimeValueSpecHashSet;
 
   // Helper classes
   class InstanceTimeComparator {
     public:
       bool Equals(const nsSMILInstanceTime* aElem1,
                     const nsSMILInstanceTime* aElem2) const;
@@ -552,17 +553,17 @@ protected:
 
   // Reset the current interval by first passing ownership to a temporary
   // variable so that if Unlink() results in us receiving a callback,
   // mCurrentInterval will be nullptr and we will be in a consistent state.
   void ResetCurrentInterval()
   {
     if (mCurrentInterval) {
       // Transfer ownership to temp var. (This sets mCurrentInterval to null.)
-      nsAutoPtr<nsSMILInterval> interval(mozilla::Move(mCurrentInterval));
+      auto interval = mozilla::Move(mCurrentInterval);
       interval->Unlink();
     }
   }
 
   //
   // Members
   //
   mozilla::dom::SVGAnimationElement* mAnimationElement; // [weak] won't outlive
@@ -595,17 +596,17 @@ protected:
   nsSMILRestartMode               mRestartMode;
   static const nsAttrValue::EnumTable sRestartModeTable[];
 
   InstanceTimeList                mBeginInstances;
   InstanceTimeList                mEndInstances;
   uint32_t                        mInstanceSerialIndex;
 
   nsSMILAnimationFunction*        mClient;
-  nsAutoPtr<nsSMILInterval>       mCurrentInterval;
+  mozilla::UniquePtr<nsSMILInterval> mCurrentInterval;
   IntervalList                    mOldIntervals;
   uint32_t                        mCurrentRepeatIteration;
   nsSMILMilestone                 mPrevRegisteredMilestone;
   static const nsSMILMilestone    sMaxMilestone;
   static const uint8_t            sMaxNumIntervals;
   static const uint8_t            sMaxNumInstanceTimes;
 
   // Set of dependent time value specs to be notified when establishing a new