From 63bc0bcbc6bdf41c06fbee3a8f300d01b835374e Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Fri, 19 Jul 2013 16:40:56 +0200 Subject: [PATCH] Bug 882543 - Retain storage for media streams accross iterations instead of reallocating. r=jlebar,roc --- content/media/MediaStreamGraph.cpp | 12 ++++++------ content/media/MediaStreamGraphImpl.h | 5 +++++ xpcom/glue/nsTArray.h | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index 369d423cf192..f3facb4c4284 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -489,10 +489,10 @@ MediaStreamGraphImpl::UpdateStreamOrderForStream(nsTArray* aStack, void MediaStreamGraphImpl::UpdateStreamOrder() { - nsTArray > oldStreams; - oldStreams.SwapElements(mStreams); - for (uint32_t i = 0; i < oldStreams.Length(); ++i) { - MediaStream* stream = oldStreams[i]; + mOldStreams.SwapElements(mStreams); + mStreams.ClearAndRetainStorage(); + for (uint32_t i = 0; i < mOldStreams.Length(); ++i) { + MediaStream* stream = mOldStreams[i]; stream->mHasBeenOrdered = false; stream->mIsConsumed = false; stream->mIsOnOrderingStack = false; @@ -504,8 +504,8 @@ MediaStreamGraphImpl::UpdateStreamOrder() } nsAutoTArray stack; - for (uint32_t i = 0; i < oldStreams.Length(); ++i) { - nsRefPtr& s = oldStreams[i]; + for (uint32_t i = 0; i < mOldStreams.Length(); ++i) { + nsRefPtr& s = mOldStreams[i]; if (!s->mAudioOutputs.IsEmpty() || !s->mVideoOutputs.IsEmpty()) { MarkConsumed(s); } diff --git a/content/media/MediaStreamGraphImpl.h b/content/media/MediaStreamGraphImpl.h index 628c1f5525a3..4a1f4c8ed475 100644 --- a/content/media/MediaStreamGraphImpl.h +++ b/content/media/MediaStreamGraphImpl.h @@ -371,6 +371,11 @@ public: nsTArray > mStreams; /** + * mOldStreams is used as temporary storage for streams when computing the + * order in which we compute them. + */ + nsTArray > mOldStreams; + /** * The current graph time for the current iteration of the RunThread control * loop. */ diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 06a6ae64f3aa..3a386477005a 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -1042,6 +1042,20 @@ public: // // Mutation methods // + // This method call the destructor on each element of the array, empties it, + // but does not shrink the array's capacity. + // + // Make sure to call Compact() if needed to avoid keeping a huge array + // around. + void ClearAndRetainStorage() { + if (base_type::mHdr == EmptyHdr()) { + return; + } + + DestructRange(0, Length()); + base_type::mHdr->mLength = 0; + } + // This method replaces a range of elements in this array. // @param start The starting index of the elements to replace. -- 2.11.4.GIT