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_ADDREF(MediaTimer)
NS_IMPL_RELEASE_WITH_DESTROY(MediaTimer, DispatchDestroy())
MediaTimer::MediaTimer(bool aFuzzy)
: mMonitor("MediaTimer Monitor")
- , mTimer(NS_NewTimer())
, mCreationTimeStamp(TimeStamp::Now())
, mUpdateScheduled(false)
, mFuzzy(aFuzzy)
{
TIMER_LOG("MediaTimer::MediaTimer");
// 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);
}
void
MediaTimer::DispatchDestroy()
{
// 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.