Bug 1550108 - Avoid decompressing entries just to check if they exist r=kmag

This will not behave exactly the same if we had previously written bad
data for the entry that would fail to decompress. I imagine this is rare
enough, and the consequences are not severe enough, that this should be
fine.

Differential Revision: https://phabricator.services.mozilla.com/D30643

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Doug Thayer 2019-09-27 22:15:01 +00:00
parent 5775d5e284
commit 5f9554635c
3 changed files with 19 additions and 2 deletions

View File

@ -353,10 +353,9 @@ nsresult nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists) {
return NS_OK;
}
UniquePtr<char[]> buf;
uint32_t len;
StartupCache* sc = StartupCache::GetSingleton();
if (sc) {
rv = sc->GetBuffer(spec.get(), &buf, &len);
*exists = sc->HasEntry(spec.get());
} else {
*exists = false;
return NS_OK;

View File

@ -230,6 +230,21 @@ nsresult GetBufferFromZipArchive(nsZipArchive* zip, bool doCRC, const char* id,
} /* anonymous namespace */
bool StartupCache::HasEntry(const char* id) {
AUTO_PROFILER_LABEL("StartupCache::HasEntry", OTHER);
MOZ_ASSERT(NS_IsMainThread(), "Startup cache only available on main thread");
WaitOnWriteThread();
if (!mStartupWriteInitiated) {
CacheEntry* entry;
mTable.Get(nsDependentCString(id), &entry);
return !!entry;
}
return mArchive && mArchive->GetItem(id);
}
// NOTE: this will not find a new entry until it has been written to disk!
// Consumer should take ownership of the resulting buffer.
nsresult StartupCache::GetBuffer(const char* id, UniquePtr<char[]>* outbuf,

View File

@ -109,6 +109,9 @@ class StartupCache : public nsIMemoryReporter {
// StartupCache methods. See above comments for a more detailed description.
// true if the archive has an entry for the buffer or not.
bool HasEntry(const char* id);
// Returns a buffer that was previously stored, caller takes ownership.
nsresult GetBuffer(const char* id, UniquePtr<char[]>* outbuf,
uint32_t* length);