From 8ae606c7bf4ba3d18c1fa4cd1f141acb48375108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 26 Jun 2020 01:17:40 +0000 Subject: [PATCH] Bug 1648095 - Don't defer the same sheet load twice. r=heycam When we call into LoadSheet when starting pending loads for a given loader, it may be the case that the original loader may still not care about the load. However some other loader will, so we can't defer this. This was also causing our state to get out of sync, because if this happened, then we'd fail to account for it in other loaders. Differential Revision: https://phabricator.services.mozilla.com/D81119 --- layout/style/Loader.cpp | 5 +++-- layout/style/SharedStyleSheetCache.cpp | 9 ++++++--- layout/style/SharedStyleSheetCache.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 5da68cafdfd8..4d9f23d21dfb 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1273,11 +1273,12 @@ nsresult Loader::LoadSheet(SheetLoadData& aLoadData, SheetState aSheetState, if (mSheets) { // If we have at least one other load ongoing, then we can defer it until // all non-pending loads are done. - if (aSheetState == SheetState::NeedsParser && aLoadData.ShouldDefer() && + if (aSheetState == SheetState::NeedsParser && + aPendingLoad == PendingLoad::No && aLoadData.ShouldDefer() && mOngoingLoadCount > mPendingLoadCount + 1) { LOG((" Deferring sheet load")); ++mPendingLoadCount; - mSheets->DeferSheetLoad(aLoadData); + mSheets->DeferSheetLoad(key, aLoadData); return NS_OK; } diff --git a/layout/style/SharedStyleSheetCache.cpp b/layout/style/SharedStyleSheetCache.cpp index 041aeba3554b..82bb19e40a28 100644 --- a/layout/style/SharedStyleSheetCache.cpp +++ b/layout/style/SharedStyleSheetCache.cpp @@ -230,10 +230,13 @@ size_t SharedStyleSheetCache::SizeOfIncludingThis( return n; } -void SharedStyleSheetCache::DeferSheetLoad(SheetLoadData& aData) { - SheetLoadDataHashKey key(aData); +void SharedStyleSheetCache::DeferSheetLoad(const SheetLoadDataHashKey& aKey, + SheetLoadData& aData) { + MOZ_ASSERT(SheetLoadDataHashKey(aData).KeyEquals(aKey)); + MOZ_DIAGNOSTIC_ASSERT(!aData.mNext, "Should only defer loads once"); + aData.mMustNotify = true; - mPendingDatas.Put(key, RefPtr{&aData}); + mPendingDatas.Put(aKey, RefPtr{&aData}); } void SharedStyleSheetCache::LoadStarted(const SheetLoadDataHashKey& aKey, diff --git a/layout/style/SharedStyleSheetCache.h b/layout/style/SharedStyleSheetCache.h index 51dd8fca34cf..f653a823417f 100644 --- a/layout/style/SharedStyleSheetCache.h +++ b/layout/style/SharedStyleSheetCache.h @@ -71,7 +71,7 @@ class SharedStyleSheetCache final : public nsIMemoryReporter { // Puts the load into the "loading" set. void LoadStarted(const SheetLoadDataHashKey&, css::SheetLoadData&); // Puts a load into the "pending" set. - void DeferSheetLoad(css::SheetLoadData&); + void DeferSheetLoad(const SheetLoadDataHashKey&, css::SheetLoadData&); enum class StartLoads { Always,