From 99c554d8dd7fc6a19beed29828e9481c58cc2df9 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 4 Dec 2019 11:22:00 +0000 Subject: [PATCH] Bug 1596129 - Introduce DatabaseNameMatchPredicate function to reduce code duplication. r=dom-workers-and-storage-reviewers,ytausky Depends on D52874 Differential Revision: https://phabricator.services.mozilla.com/D52875 --HG-- extra : moz-landing-system : lando --- dom/indexedDB/IndexedDatabaseManager.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp index 6f16719cdb8e..54375331dcff 100644 --- a/dom/indexedDB/IndexedDatabaseManager.cpp +++ b/dom/indexedDB/IndexedDatabaseManager.cpp @@ -209,6 +209,13 @@ void MaxPreloadExtraRecordsPrefChangeCallback(const char* aPrefName, // require adaptations in ActorsParent.cpp } +auto DatabaseNameMatchPredicate(const nsAString* const aName) { + MOZ_ASSERT(aName); + return [aName](const auto& fileManager) { + return fileManager->DatabaseName() == *aName; + }; +} + } // namespace IndexedDatabaseManager::IndexedDatabaseManager() @@ -864,9 +871,7 @@ already_AddRefed FileManagerInfo::GetFileManager( const auto end = managers.cend(); const auto foundIt = - std::find_if(managers.cbegin(), end, [&aName](const auto& fileManager) { - return fileManager->DatabaseName() == aName; - }); + std::find_if(managers.cbegin(), end, DatabaseNameMatchPredicate(&aName)); return foundIt != end ? RefPtr{*foundIt}.forget() : nullptr; } @@ -919,9 +924,7 @@ void FileManagerInfo::InvalidateAndRemoveFileManager( auto& managers = GetArray(aPersistenceType); const auto end = managers.cend(); const auto foundIt = - std::find_if(managers.cbegin(), end, [&aName](const auto& fileManager) { - return fileManager->DatabaseName() == aName; - }); + std::find_if(managers.cbegin(), end, DatabaseNameMatchPredicate(&aName)); if (foundIt != end) { (*foundIt)->Invalidate();