Bug 1163597 - MediaStreamGraphImpl::RecomputeBlockingAt: optimization in the number of loops for the mStreams array, r=padenot
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 11 May 2015 18:50:55 +0100
changeset 243534 3f13ac0125814c0338f5524f7ed885945cce35ad
parent 243533 01adfca321668748854e09657bd80077e7318140
child 243535 f1dd5e362984ceed7641c43a5a82858dfd8cb4e9
push id28741
push userkwierso@gmail.com
push dateTue, 12 May 2015 23:24:40 +0000
treeherdermozilla-central@d476776d920d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1163597
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 1163597 - MediaStreamGraphImpl::RecomputeBlockingAt: optimization in the number of loops for the mStreams array, r=padenot
dom/media/MediaStreamGraph.cpp
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -909,23 +909,39 @@ MediaStreamGraphImpl::MarkStreamBlocking
 }
 
 void
 MediaStreamGraphImpl::RecomputeBlockingAt(const nsTArray<MediaStream*>& aStreams,
                                           GraphTime aTime,
                                           GraphTime aEndBlockingDecisions,
                                           GraphTime* aEnd)
 {
+  class MOZ_STACK_CLASS AfterLoop
+  {
+  public:
+    AfterLoop(MediaStream* aStream, GraphTime& aTime)
+      : mStream(aStream)
+      , mTime(aTime)
+    {}
+
+    ~AfterLoop()
+    {
+      mStream->mBlocked.SetAtAndAfter(mTime, mStream->mBlockInThisPhase);
+    }
+
+  private:
+    MediaStream* mStream;
+    GraphTime& mTime;
+  };
+
   for (uint32_t i = 0; i < aStreams.Length(); ++i) {
     MediaStream* stream = aStreams[i];
     stream->mBlockInThisPhase = false;
-  }
-
-  for (uint32_t i = 0; i < aStreams.Length(); ++i) {
-    MediaStream* stream = aStreams[i];
+
+    AfterLoop al(stream, aTime);
 
     if (stream->mFinished) {
       GraphTime endTime = StreamTimeToGraphTime(stream,
          stream->GetStreamBuffer().GetAllTracksEnd());
       if (endTime <= aTime) {
         STREAM_LOG(PR_LOG_DEBUG+1, ("MediaStream %p is blocked due to being finished", stream));
         // We'll block indefinitely
         MarkStreamBlocking(stream);
@@ -951,22 +967,18 @@ MediaStreamGraphImpl::RecomputeBlockingA
     bool underrun = WillUnderrun(stream, aTime, aEndBlockingDecisions, aEnd);
     if (underrun) {
       // We'll block indefinitely
       MarkStreamBlocking(stream);
       *aEnd = std::min(*aEnd, aEndBlockingDecisions);
       continue;
     }
   }
+
   NS_ASSERTION(*aEnd > aTime, "Failed to advance!");
-
-  for (uint32_t i = 0; i < aStreams.Length(); ++i) {
-    MediaStream* stream = aStreams[i];
-    stream->mBlocked.SetAtAndAfter(aTime, stream->mBlockInThisPhase);
-  }
 }
 
 void
 MediaStreamGraphImpl::NotifyHasCurrentData(MediaStream* aStream)
 {
   if (!aStream->mNotifiedHasCurrentData && aStream->mHasCurrentData) {
     for (uint32_t j = 0; j < aStream->mListeners.Length(); ++j) {
       MediaStreamListener* l = aStream->mListeners[j];