mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
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:
parent
5775d5e284
commit
5f9554635c
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user