Bug 1425623 - Don't allocate array on the heap. r=padenot

Instead allocate it on the stack and provide it as out parameter.

MozReview-Commit-ID: 9fSJ68EfAga

--HG--
extra : rebase_source : 81430b45e4341d0f4208097f021c2a917e8e2645
This commit is contained in:
Jean-Yves Avenard 2017-12-17 15:47:44 +01:00
Родитель dc98cb00b0
Коммит 0a4ce68473
2 изменённых файлов: 17 добавлений и 18 удалений

Просмотреть файл

@ -1141,7 +1141,7 @@ MediaStreamGraphImpl::UpdateGraph(GraphTime aEndBlockingDecisions)
MOZ_ASSERT(OnGraphThread());
MOZ_ASSERT(aEndBlockingDecisions >= mProcessedTime);
// The next state computed time can be the same as the previous: it
// means the driver would be have been blocking indefinitly, but the graph has
// means the driver would have been blocking indefinitly, but the graph has
// been woken up right after having been to sleep.
MOZ_ASSERT(aEndBlockingDecisions >= mStateComputedTime);
@ -1150,13 +1150,10 @@ MediaStreamGraphImpl::UpdateGraph(GraphTime aEndBlockingDecisions)
bool ensureNextIteration = false;
// Grab pending stream input and compute blocking time
// TODO: Ensure that heap memory allocations isn't going to be a problem.
// Maybe modify code to use nsAutoTArray as out parameters.
nsTArray<RefPtr<SourceMediaStream::NotifyPullPromise>> promises;
AutoTArray<RefPtr<SourceMediaStream::NotifyPullPromise>, 64> promises;
for (MediaStream* stream : mStreams) {
if (SourceMediaStream* is = stream->AsSourceStream()) {
promises.AppendElements(
is->PullNewData(aEndBlockingDecisions, &ensureNextIteration));
ensureNextIteration |= is->PullNewData(aEndBlockingDecisions, promises);
}
}
@ -2712,15 +2709,14 @@ SourceMediaStream::SetPullEnabled(bool aEnabled)
}
}
nsTArray<RefPtr<SourceMediaStream::NotifyPullPromise>>
SourceMediaStream::PullNewData(StreamTime aDesiredUpToTime,
bool* aEnsureNextIteration)
bool
SourceMediaStream::PullNewData(
StreamTime aDesiredUpToTime,
nsTArray<RefPtr<SourceMediaStream::NotifyPullPromise>>& aPromises)
{
// 2 is the average number of listeners per SourceMediaStream.
nsTArray<RefPtr<SourceMediaStream::NotifyPullPromise>> promises(2);
MutexAutoLock lock(mMutex);
if (!mPullEnabled || mFinished) {
return promises;
return false;
}
// Compute how much stream time we'll need assuming we don't block
// the stream at all.
@ -2732,9 +2728,8 @@ SourceMediaStream::PullNewData(StreamTime aDesiredUpToTime,
GraphImpl()->MediaTimeToSeconds(t),
GraphImpl()->MediaTimeToSeconds(current)));
if (t <= current) {
return promises;
return false;
}
*aEnsureNextIteration = true;
#ifdef DEBUG
if (mListeners.Length() == 0) {
LOG(
@ -2750,10 +2745,10 @@ SourceMediaStream::PullNewData(StreamTime aDesiredUpToTime,
MediaStreamListener* l = mListeners[j];
{
MutexAutoUnlock unlock(mMutex);
promises.AppendElement(l->AsyncNotifyPull(GraphImpl(), t));
aPromises.AppendElement(l->AsyncNotifyPull(GraphImpl(), t));
}
}
return promises;
return true;
}
void

Просмотреть файл

@ -702,10 +702,14 @@ public:
/**
* Call all MediaStreamListeners to request new data via the NotifyPull API
* (if enabled).
* aDesiredUpToTime (in): end time of new data requested.
* aPromises (out): NotifyPullPromises if async API is enabled.
*
* Returns true if new data is about to be added.
*/
typedef MozPromise<bool, bool, true /* is exclusive */ > NotifyPullPromise;
nsTArray<RefPtr<NotifyPullPromise>> PullNewData(StreamTime aDesiredUpToTime,
bool* aEnsureNextIteration);
bool PullNewData(StreamTime aDesiredUpToTime,
nsTArray<RefPtr<NotifyPullPromise>>& aPromises);
/**
* Extract any state updates pending in the stream, and apply them.