Bug 1163585 - Small improvement of the use of nsTArray in MSG::UpdateCurrentTimeForStreams, r=padenot
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 11 May 2015 15:06:44 +0100
changeset 243363 6b1f47f5127108307a513220a0db57a011ed24a0
parent 243362 ce91b46dd81d87316fe1482993c99204860bf962
child 243364 bad7af6079e93cdac37461f8e55ca0a7a528230b
push id28738
push usercbook@mozilla.com
push dateTue, 12 May 2015 14:11:31 +0000
treeherdermozilla-central@bedce1b405a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1163585
milestone40.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 1163585 - Small improvement of the use of nsTArray in MSG::UpdateCurrentTimeForStreams, r=padenot
dom/media/MediaStreamGraph.cpp
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -395,25 +395,23 @@ GraphTime
 MediaStreamGraphImpl::IterationEnd()
 {
   return CurrentDriver()->IterationEnd();
 }
 
 void
 MediaStreamGraphImpl::UpdateCurrentTimeForStreams(GraphTime aPrevCurrentTime, GraphTime aNextCurrentTime)
 {
-  nsTArray<MediaStream*> streamsReadyToFinish;
-  nsAutoTArray<bool,800> streamHasOutput;
+  nsAutoTArray<MediaStream*, 800> streamsReadyToFinish;
+  nsAutoTArray<MediaStream*, 800> streamsWithOutput;
 
   nsTArray<MediaStream*>* runningAndSuspendedPair[2];
   runningAndSuspendedPair[0] = &mStreams;
   runningAndSuspendedPair[1] = &mSuspendedStreams;
 
-  streamHasOutput.SetLength(mStreams.Length());
-
   for (uint32_t array = 0; array < 2; array++) {
     for (uint32_t i = 0; i < runningAndSuspendedPair[array]->Length(); ++i) {
       MediaStream* stream = (*runningAndSuspendedPair[array])[i];
 
       // Calculate blocked time and fire Blocked/Unblocked events
       GraphTime blockedTime = 0;
       GraphTime t = aPrevCurrentTime;
       // include |nextCurrentTime| to ensure NotifyBlockingChanged() is called
@@ -440,39 +438,39 @@ MediaStreamGraphImpl::UpdateCurrentTimeF
       stream->AdvanceTimeVaryingValuesToCurrentTime(aNextCurrentTime,
                                                     blockedTime);
       // Advance mBlocked last so that implementations of
       // AdvanceTimeVaryingValuesToCurrentTime can rely on the value of
       // mBlocked.
       stream->mBlocked.AdvanceCurrentTime(aNextCurrentTime);
 
       if (runningAndSuspendedPair[array] == &mStreams) {
-        streamHasOutput[i] = blockedTime < aNextCurrentTime - aPrevCurrentTime;
+        bool streamHasOutput = blockedTime < aNextCurrentTime - aPrevCurrentTime;
         // Make this an assertion when bug 957832 is fixed.
         NS_WARN_IF_FALSE(
-          !streamHasOutput[i] || !stream->mNotifiedFinished,
+          !streamHasOutput || !stream->mNotifiedFinished,
           "Shouldn't have already notified of finish *and* have output!");
 
+        if (streamHasOutput) {
+          streamsWithOutput.AppendElement(stream);
+        }
+
         if (stream->mFinished && !stream->mNotifiedFinished) {
           streamsReadyToFinish.AppendElement(stream);
         }
       }
       STREAM_LOG(PR_LOG_DEBUG + 1,
                  ("MediaStream %p bufferStartTime=%f blockedTime=%f", stream,
                   MediaTimeToSeconds(stream->mBufferStartTime),
                   MediaTimeToSeconds(blockedTime)));
     }
   }
 
-
-  for (uint32_t i = 0; i < streamHasOutput.Length(); ++i) {
-    if (!streamHasOutput[i]) {
-      continue;
-    }
-    MediaStream* stream = mStreams[i];
+  for (uint32_t i = 0; i < streamsWithOutput.Length(); ++i) {
+    MediaStream* stream = streamsWithOutput[i];
     for (uint32_t j = 0; j < stream->mListeners.Length(); ++j) {
       MediaStreamListener* l = stream->mListeners[j];
       l->NotifyOutput(this, IterationEnd());
     }
   }
 
   for (uint32_t i = 0; i < streamsReadyToFinish.Length(); ++i) {
     MediaStream* stream = streamsReadyToFinish[i];