Bug 1693541 - Improve uses of nsBaseHashtable and descendants and avoid multiple subsequent lookups in security/manager/ssl/DataStorage.cpp. r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D106102
This commit is contained in:
Simon Giesecke 2021-02-26 11:36:42 +00:00
parent d2cf2fa5cc
commit 2a40dba629

View File

@ -111,12 +111,8 @@ already_AddRefed<DataStorage> DataStorage::GetFromRawFileName(
sDataStorages = new DataStorages();
ClearOnShutdown(&sDataStorages);
}
RefPtr<DataStorage> storage;
if (!sDataStorages->Get(aFilename, getter_AddRefs(storage))) {
storage = new DataStorage(aFilename);
sDataStorages->InsertOrUpdate(aFilename, RefPtr{storage});
}
return storage.forget();
return do_AddRef(sDataStorages->LookupOrInsertWith(
aFilename, [&] { return RefPtr{new DataStorage(aFilename)}; }));
}
// static
@ -482,11 +478,8 @@ DataStorage::Reader::Run() {
if (NS_SUCCEEDED(parseRV)) {
// It could be the case that a newer entry was added before
// we got around to reading the file. Don't overwrite new entries.
Entry newerEntry;
bool present = mDataStorage->mPersistentDataTable.Get(key, &newerEntry);
if (!present) {
mDataStorage->mPersistentDataTable.InsertOrUpdate(key, entry);
}
mDataStorage->mPersistentDataTable.LookupOrInsert(key,
std::move(entry));
}
} while (true);