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
This commit is contained in:
Simon Giesecke 2019-12-04 11:22:00 +00:00
Родитель 445f39a14b
Коммит 99c554d8dd
1 изменённых файлов: 9 добавлений и 6 удалений

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

@ -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<FileManager> 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<FileManager>{*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();