Bug 1439047 - Part 2: Cleanup StartupCache::PutBuffer hashtable usage. r=froydnj

This switches over to using `LookupForAdd` which allows us to avoid a second
lookup when adding the entry. Addtionally `nsDependentCString` is used to
avoid copying the id string when looking up the entry.

--HG--
extra : rebase_source : 2dbb54fb992f4c79347150198af61438ee5b4eec
extra : source : 718961d941d4d495426e59c6b5044302059489f9
This commit is contained in:
Eric Rahm 2018-02-16 15:58:30 -08:00
Родитель 7337adec45
Коммит 0e7bb34ef8
1 изменённых файлов: 6 добавлений и 5 удалений

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

@ -310,11 +310,11 @@ StartupCache::PutBuffer(const char* id, UniquePtr<char[]>&& inbuf, uint32_t len)
return NS_ERROR_NOT_AVAILABLE;
}
nsCString idStr(id);
nsDependentCString idStr(id);
// Cache it for now, we'll write all together later.
CacheEntry* entry;
auto entry = mTable.LookupForAdd(idStr);
if (mTable.Get(idStr)) {
if (entry) {
NS_WARNING("Existing entry in StartupCache.");
// Double-caching is undesirable but not an error.
return NS_OK;
@ -327,8 +327,9 @@ StartupCache::PutBuffer(const char* id, UniquePtr<char[]>&& inbuf, uint32_t len)
}
#endif
entry = new CacheEntry(Move(inbuf), len);
mTable.Put(idStr, entry);
entry.OrInsert([&inbuf, &len]() {
return new CacheEntry(Move(inbuf), len);
});
mPendingWrites.AppendElement(idStr);
return ResetStartupWriteTimer();
}