Reduce calls to CFURLCacheCopySharedURLCache
Created attachment 230655 [details] Patch
My only concern here would be if someone was calling CFURLCacheSetSharedCache or [NSURLCache setSharedURLCache] after we cache the url ref in the static. I could't find any such callers though.
Comment on attachment 230655 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=230655&action=review > Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm:89 > + static RetainPtr<CFURLCacheRef> cache = adoptCF(CFURLCacheCopySharedURLCache()); This can't be a RetainPtr, because we don't want exit time destructors. A plain pointer would be appropriate. An ASSERT in debug builds would ensure that we don't break this optimization, although that may be overkill.
Created attachment 230675 [details] Patch with assert and raw pointer
Comment on attachment 230675 [details] Patch with assert and raw pointer View in context: https://bugs.webkit.org/attachment.cgi?id=230675&action=review > Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm:89 > + static CFURLCacheRef cache = CFURLCacheCopySharedURLCache(); I'd also add ASSERT(isMainThread()) here, as this initialization is not thread safe.
<rdar://problem/16806694>
Committed r168231: <http://trac.webkit.org/changeset/168231>
Comment on attachment 230675 [details] Patch with assert and raw pointer View in context: https://bugs.webkit.org/attachment.cgi?id=230675&action=review > Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm:93 > +#if !ASSERT_DISABLED > + RetainPtr<CFURLCacheRef> currentCache = adoptCF(CFURLCacheCopySharedURLCache()); > + ASSERT(cache == currentCache.get()); > +#endif To avoid this ugly if, just get rid of the local variable: ASSERT(currentCache == adoptCF(CFURLCacheCopySharedURLCache())); Also no need for the call to get() when doing ==.
(In reply to comment #8) > (From update of attachment 230675 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=230675&action=review > > > Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm:93 > > +#if !ASSERT_DISABLED > > + RetainPtr<CFURLCacheRef> currentCache = adoptCF(CFURLCacheCopySharedURLCache()); > > + ASSERT(cache == currentCache.get()); > > +#endif > > To avoid this ugly if, just get rid of the local variable: > > ASSERT(currentCache == adoptCF(CFURLCacheCopySharedURLCache())); > > Also no need for the call to get() when doing ==. Yes, this looks much better. I landed this in <http://trac.webkit.org/changeset/168250>.