Bug 1499849 - make FileReader timers slightly more efficient; r=baku
authorNathan Froyd <froydnj@mozilla.com>
Wed, 17 Oct 2018 19:57:35 -0400
changeset 490128 8b037400fdbed6b9fd14c36a8b32acd78a742e1d
parent 490127 18c94f6d82046c4986c0c55f41a6fbf4039c8288
child 490129 8bdbb72ad61b6272b3b7faed01383bb7c5fe7e72
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersbaku
bugs1499849
milestone64.0a1
Bug 1499849 - make FileReader timers slightly more efficient; r=baku 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.
dom/file/FileReader.cpp
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -526,24 +526,23 @@ FileReader::WrapObject(JSContext* aCx, J
 {
   return FileReader_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 void
 FileReader::StartProgressEventTimer()
 {
   if (!mProgressNotifier) {
-    mProgressNotifier = NS_NewTimer();
+    mProgressNotifier = NS_NewTimer(mTarget);
   }
 
   if (mProgressNotifier) {
     mProgressEventWasDelayed = false;
     mTimerIsActive = true;
     mProgressNotifier->Cancel();
-    mProgressNotifier->SetTarget(mTarget);
     mProgressNotifier->InitWithCallback(this, NS_PROGRESS_EVENT_INTERVAL,
                                         nsITimer::TYPE_ONE_SHOT);
   }
 }
 
 void
 FileReader::ClearProgressEventTimer()
 {