Bug 1622114 - Improve array manipulation in CleanupIDBTransactions. r=dom-workers-and-storage-reviewers,smaug,asuth

- Do not remove elements one-by-one but use remove-erase pattern.
- Move mPendingIDBTransactions array instead of copying.

Differential Revision: https://phabricator.services.mozilla.com/D67159

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Simon Giesecke 2020-03-19 12:55:12 +00:00
Родитель 5de3c1b41d
Коммит 5621715961
1 изменённых файлов: 18 добавлений и 15 удалений

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

@ -417,24 +417,27 @@ void CycleCollectedJSContext::CleanupIDBTransactions(uint32_t aRecursionDepth) {
nsTArray<PendingIDBTransactionData> localQueue =
std::move(mPendingIDBTransactions);
for (uint32_t i = 0; i < localQueue.Length(); ++i) {
PendingIDBTransactionData& data = localQueue[i];
if (data.mRecursionDepth != aRecursionDepth) {
continue;
}
localQueue.RemoveElementsAt(
std::remove_if(localQueue.begin(), localQueue.end(),
[aRecursionDepth](PendingIDBTransactionData& data) {
if (data.mRecursionDepth != aRecursionDepth) {
return false;
}
{
nsCOMPtr<nsIRunnable> transaction = std::move(data.mTransaction);
transaction->Run();
}
{
nsCOMPtr<nsIRunnable> transaction =
std::move(data.mTransaction);
transaction->Run();
}
localQueue.RemoveElementAt(i--);
}
return true;
}),
localQueue.end());
// If the queue has events in it now, they were added from something we
// called, so they belong at the end of the queue.
localQueue.AppendElements(mPendingIDBTransactions);
localQueue.SwapElements(mPendingIDBTransactions);
// If mPendingIDBTransactions has events in it now, they were added from
// something we called, so they belong at the end of the queue.
localQueue.AppendElements(std::move(mPendingIDBTransactions));
mPendingIDBTransactions = std::move(localQueue);
mDoingStableStates = false;
}