Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 5f95546

Browse files
committed
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
1 parent 5775d5e commit 5f95546

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

dom/xul/nsXULPrototypeCache.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,9 @@ nsresult nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists) {
353353
return NS_OK;
354354
}
355355
UniquePtr<char[]> buf;
356-
uint32_t len;
357356
StartupCache* sc = StartupCache::GetSingleton();
358357
if (sc) {
359-
rv = sc->GetBuffer(spec.get(), &buf, &len);
358+
*exists = sc->HasEntry(spec.get());
360359
} else {
361360
*exists = false;
362361
return NS_OK;

startupcache/StartupCache.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ nsresult GetBufferFromZipArchive(nsZipArchive* zip, bool doCRC, const char* id,
230230

231231
} /* anonymous namespace */
232232

233+
bool StartupCache::HasEntry(const char* id) {
234+
AUTO_PROFILER_LABEL("StartupCache::HasEntry", OTHER);
235+
236+
MOZ_ASSERT(NS_IsMainThread(), "Startup cache only available on main thread");
237+
WaitOnWriteThread();
238+
239+
if (!mStartupWriteInitiated) {
240+
CacheEntry* entry;
241+
mTable.Get(nsDependentCString(id), &entry);
242+
return !!entry;
243+
}
244+
245+
return mArchive && mArchive->GetItem(id);
246+
}
247+
233248
// NOTE: this will not find a new entry until it has been written to disk!
234249
// Consumer should take ownership of the resulting buffer.
235250
nsresult StartupCache::GetBuffer(const char* id, UniquePtr<char[]>* outbuf,

startupcache/StartupCache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class StartupCache : public nsIMemoryReporter {
109109

110110
// StartupCache methods. See above comments for a more detailed description.
111111

112+
// true if the archive has an entry for the buffer or not.
113+
bool HasEntry(const char* id);
114+
112115
// Returns a buffer that was previously stored, caller takes ownership.
113116
nsresult GetBuffer(const char* id, UniquePtr<char[]>* outbuf,
114117
uint32_t* length);

0 commit comments

Comments
 (0)