PassRefPtr<ArchiveResource> DocumentLoader::subresource(const KURL& url) const { if (!isCommitted()) return 0; Document* doc = m_frame->document(); if (!doc) return archiveResourceForURL(url); CachedResource* resource = doc->docLoader()->cachedResource(url); if (!resource || resource->preloadResult() == CachedResource::PreloadReferenced) return archiveResourceForURL(url); return ArchiveResource::create(resource->data(), url, resource->response()); }
void DocLoader::clearPreloads() { #if PRELOAD_DEBUG printPreloadStats(); #endif ListHashSet<CachedResource*>::iterator end = m_preloads.end(); for (ListHashSet<CachedResource*>::iterator it = m_preloads.begin(); it != end; ++it) { CachedResource* res = *it; res->decreasePreloadCount(); if (res->canDelete() && !res->inCache()) delete res; else if (res->preloadResult() == CachedResource::PreloadNotReferenced) cache()->remove(res); } m_preloads.clear(); }
void CachedResourceLoader::clearPreloads() { #if PRELOAD_DEBUG printPreloadStats(); #endif if (!m_preloads) return; ListHashSet<CachedResource*>::iterator end = m_preloads->end(); for (ListHashSet<CachedResource*>::iterator it = m_preloads->begin(); it != end; ++it) { CachedResource* res = *it; res->decreasePreloadCount(); bool deleted = res->deleteIfPossible(); if (!deleted && res->preloadResult() == CachedResource::PreloadNotReferenced) memoryCache()->remove(res); } m_preloads.clear(); }
void CachedResourceLoader::printPreloadStats() { unsigned scripts = 0; unsigned scriptMisses = 0; unsigned stylesheets = 0; unsigned stylesheetMisses = 0; unsigned images = 0; unsigned imageMisses = 0; ListHashSet<CachedResource*>::iterator end = m_preloads.end(); for (ListHashSet<CachedResource*>::iterator it = m_preloads.begin(); it != end; ++it) { CachedResource* res = *it; if (res->preloadResult() == CachedResource::PreloadNotReferenced) printf("!! UNREFERENCED PRELOAD %s\n", res->url().latin1().data()); else if (res->preloadResult() == CachedResource::PreloadReferencedWhileComplete) printf("HIT COMPLETE PRELOAD %s\n", res->url().latin1().data()); else if (res->preloadResult() == CachedResource::PreloadReferencedWhileLoading) printf("HIT LOADING PRELOAD %s\n", res->url().latin1().data()); if (res->type() == CachedResource::Script) { scripts++; if (res->preloadResult() < CachedResource::PreloadReferencedWhileLoading) scriptMisses++; } else if (res->type() == CachedResource::CSSStyleSheet) { stylesheets++; if (res->preloadResult() < CachedResource::PreloadReferencedWhileLoading) stylesheetMisses++; } else { images++; if (res->preloadResult() < CachedResource::PreloadReferencedWhileLoading) imageMisses++; } if (res->errorOccurred()) memoryCache()->remove(res); res->decreasePreloadCount(); } m_preloads.clear(); if (scripts) printf("SCRIPTS: %d (%d hits, hit rate %d%%)\n", scripts, scripts - scriptMisses, (scripts - scriptMisses) * 100 / scripts); if (stylesheets) printf("STYLESHEETS: %d (%d hits, hit rate %d%%)\n", stylesheets, stylesheets - stylesheetMisses, (stylesheets - stylesheetMisses) * 100 / stylesheets); if (images) printf("IMAGES: %d (%d hits, hit rate %d%%)\n", images, images - imageMisses, (images - imageMisses) * 100 / images); }