From b024b00b94818ffe701570c97804711fe77fceac Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Mon, 15 Apr 2019 15:41:15 +0000 Subject: [PATCH] Bug 1515216, ensure IdleTaskRunners are added only once to RefreshDriver's idle runnable list, r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D27424 --HG-- extra : moz-landing-system : lando --- layout/base/nsRefreshDriver.cpp | 10 ++++++++-- layout/base/nsRefreshDriver.h | 4 ++-- xpcom/threads/IdleTaskRunner.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 0037cf3bcb76..46c951e4a118 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -1713,10 +1713,16 @@ struct RunnableWithDelay { static AutoTArray* sPendingIdleRunnables = nullptr; -void nsRefreshDriver::DispatchIdleRunnableAfterTick(nsIRunnable* aRunnable, - uint32_t aDelay) { +void nsRefreshDriver::DispatchIdleRunnableAfterTickUnlessExists( + nsIRunnable* aRunnable, uint32_t aDelay) { if (!sPendingIdleRunnables) { sPendingIdleRunnables = new AutoTArray(); + } else { + for (uint32_t i = 0; i < sPendingIdleRunnables->Length(); ++i) { + if ((*sPendingIdleRunnables)[i].mRunnable == aRunnable) { + return; + } + } } RunnableWithDelay rwd = {aRunnable, aDelay}; diff --git a/layout/base/nsRefreshDriver.h b/layout/base/nsRefreshDriver.h index 0e73047a536d..8763be8ceff1 100644 --- a/layout/base/nsRefreshDriver.h +++ b/layout/base/nsRefreshDriver.h @@ -415,8 +415,8 @@ class nsRefreshDriver final : public mozilla::layers::TransactionIdAllocator, */ static mozilla::Maybe GetNextTickHint(); - static void DispatchIdleRunnableAfterTick(nsIRunnable* aRunnable, - uint32_t aDelay); + static void DispatchIdleRunnableAfterTickUnlessExists(nsIRunnable* aRunnable, + uint32_t aDelay); static void CancelIdleRunnable(nsIRunnable* aRunnable); void NotifyDOMContentLoaded(); diff --git a/xpcom/threads/IdleTaskRunner.cpp b/xpcom/threads/IdleTaskRunner.cpp index d76fa24d78c5..038efad6617a 100644 --- a/xpcom/threads/IdleTaskRunner.cpp +++ b/xpcom/threads/IdleTaskRunner.cpp @@ -119,7 +119,7 @@ void IdleTaskRunner::Schedule(bool aAllowIdleDispatch) { TimeStamp hint = nsRefreshDriver::GetIdleDeadlineHint(now); if (hint != now) { // RefreshDriver is ticking, let it schedule the idle dispatch. - nsRefreshDriver::DispatchIdleRunnableAfterTick(this, mDelay); + nsRefreshDriver::DispatchIdleRunnableAfterTickUnlessExists(this, mDelay); // Ensure we get called at some point, even if RefreshDriver is stopped. SetTimerInternal(mDelay); } else {