Allow WTF::map to use any class that is iterable and has a size getter
[WebKit-https.git] / Source / WebCore / loader / appcache / ApplicationCacheHost.cpp
index d08c3f1..d2b04ff 100644 (file)
@@ -327,15 +327,11 @@ void ApplicationCacheHost::stopDeferringEvents()
 
 Vector<ApplicationCacheHost::ResourceInfo> ApplicationCacheHost::resourceList()
 {
-    Vector<ResourceInfo> result;
-
     auto* cache = applicationCache();
     if (!cache || !cache->isComplete())
-        return result;
-
-    result.reserveInitialCapacity(cache->resources().size());
+        return { };
 
-    for (auto& urlAndResource : cache->resources()) {
+    return WTF::map(cache->resources(), [] (auto& urlAndResource) -> ApplicationCacheHost::ResourceInfo {
         ASSERT(urlAndResource.value);
         auto& resource = *urlAndResource.value;
 
@@ -346,10 +342,8 @@ Vector<ApplicationCacheHost::ResourceInfo> ApplicationCacheHost::resourceList()
         bool isForeign = type & ApplicationCacheResource::Foreign;
         bool isFallback = type & ApplicationCacheResource::Fallback;
 
-        result.uncheckedAppend({ resource.url(), isMaster, isManifest, isFallback, isForeign, isExplicit, resource.estimatedSizeInStorage() });
-    }
-
-    return result;
+        return { resource.url(), isMaster, isManifest, isFallback, isForeign, isExplicit, resource.estimatedSizeInStorage() };
+    });
 }
 
 ApplicationCacheHost::CacheInfo ApplicationCacheHost::applicationCacheInfo()