From b87d2b06628f9faea1a8d158aa77089a25f06f31 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 9 Feb 2021 18:19:36 +0000 Subject: [PATCH] Bug 1682536 - Use references/NotNull for QuotaObject. r=dom-workers-and-storage-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D99780 --- dom/quota/ActorsParent.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 8477c54bff5f..b3602f5af556 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -841,7 +841,7 @@ class OriginInfo final { void LockedPersist(); - nsDataHashtable mQuotaObjects; + nsDataHashtable> mQuotaObjects; ClientUsageArray mClientUsages; GroupInfo* mGroupInfo; const nsCString mOrigin; @@ -4341,15 +4341,16 @@ already_AddRefed QuotaManager::GetQuotaObject( // We need this extra raw pointer because we can't assign to the smart // pointer directly since QuotaObject::AddRef would try to acquire the same // mutex. - QuotaObject* quotaObject; - if (!originInfo->mQuotaObjects.Get(path, "aObject)) { - // Create a new QuotaObject. - quotaObject = new QuotaObject(originInfo, aClientType, path, fileSize); - - // Put it to the hashtable. The hashtable is not responsible to delete - // the QuotaObject. - originInfo->mQuotaObjects.Put(path, quotaObject); - } + const NotNull quotaObject = + originInfo->mQuotaObjects.WithEntryHandle( + path, [&](auto&& entryHandle) { + return entryHandle.OrInsertWith([&] { + // Create a new QuotaObject. The hashtable is not responsible to + // delete the QuotaObject. + return WrapNotNullUnchecked( + new QuotaObject(originInfo, aClientType, path, fileSize)); + }); + }); // Addref the QuotaObject and move the ownership to the result. This must // happen before we unlock!