Bug 1499850 - make MediaTimer slightly more efficient; r=pehrsons
authorNathan Froyd <froydnj@mozilla.com>
Thu, 18 Oct 2018 07:00:11 -0400
changeset 490222 0162bb225b88cfda9b702d88464d48fbf1f372ee
parent 490221 9e81f9458926dbb1796ac5c3c0b06fa1ee1d10e9
child 490223 2da6504c901e9474566aa1663d907bd58bed9edb
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
Bug 1499850 - make MediaTimer slightly more efficient; r=pehrsons Instead of creating a timer and then setting the timer's target, we can determine the timer's target and pass it in directly when the timer is created. This reordering of steps is slightly more efficient, since SetTarget() is both a virtual call and requires locking, both of which can be skipped if we know the target at timer creation time.
--- a/dom/media/MediaTimer.cpp
+++ b/dom/media/MediaTimer.cpp
@@ -16,29 +16,28 @@
 namespace mozilla {
 NS_IMPL_RELEASE_WITH_DESTROY(MediaTimer, DispatchDestroy())
 MediaTimer::MediaTimer(bool aFuzzy)
   : mMonitor("MediaTimer Monitor")
-  , mTimer(NS_NewTimer())
   , mCreationTimeStamp(TimeStamp::Now())
   , mUpdateScheduled(false)
   , mFuzzy(aFuzzy)
   // Use the SharedThreadPool to create an nsIThreadPool with a maximum of one
   // thread, which is equivalent to an nsIThread for our purposes.
   RefPtr<SharedThreadPool> threadPool(
     SharedThreadPool::Get(NS_LITERAL_CSTRING("MediaTimer"), 1));
   mThread = threadPool.get();
-  mTimer->SetTarget(mThread);
+  mTimer = NS_NewTimer(mThread);
   // Hold a strong reference to the thread so that it doesn't get deleted in
   // Destroy(), which may run completely before the stack if Dispatch() begins
   // to unwind.