Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1439047 - Part 2: Cleanup StartupCache::PutBuffer hashtable usage…
Browse files Browse the repository at this point in the history
…. 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.
  • Loading branch information
EricRahm committed Feb 16, 2018
1 parent 15d2793 commit 0421ef2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions startupcache/StartupCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down

0 comments on commit 0421ef2

Please sign in to comment.