Bug 1693541 - Improve uses of nsBaseHashtable and descendants and avoid multiple subsequent lookups in uriloader. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D106100
This commit is contained in:
Simon Giesecke 2021-02-26 11:36:40 +00:00
Родитель 43bacaa3f9
Коммит 165b32796c
1 изменённых файлов: 6 добавлений и 12 удалений

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

@ -220,18 +220,12 @@ ContentHandlerService::ExistsForProtocol(const nsACString& aProtocolScheme,
NS_IMETHODIMP ContentHandlerService::GetTypeFromExtension(
const nsACString& aFileExtension, nsACString& _retval) {
nsCString* cachedType = nullptr;
if (!!mExtToTypeMap.Get(aFileExtension, &cachedType) && !!cachedType) {
_retval.Assign(*cachedType);
return NS_OK;
}
nsCString type;
mHandlerServiceChild->SendGetTypeFromExtension(nsCString(aFileExtension),
&type);
_retval.Assign(type);
mExtToTypeMap.InsertOrUpdate(nsCString(aFileExtension),
MakeUnique<nsCString>(type));
_retval.Assign(*mExtToTypeMap.LookupOrInsertWith(aFileExtension, [&] {
nsCString type;
mHandlerServiceChild->SendGetTypeFromExtension(nsCString(aFileExtension),
&type);
return MakeUnique<nsCString>(type);
}));
return NS_OK;
}