Title: [201395] trunk/Source/WebKit2
Revision
201395
Author
[email protected]
Date
2016-05-25 12:17:57 -0700 (Wed, 25 May 2016)

Log Message

Simplify a few lambda captures in the network cache code
https://bugs.webkit.org/show_bug.cgi?id=158076

Reviewed by Antti Koivisto.

Simplify a few lambda captures in the network cache code by WTFMoving
upon capture.

* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
(WebKit::NetworkCache::SpeculativeLoadManager::retrieve):
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveEntryFromStorage):
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h:
* NetworkProcess/cache/NetworkCacheStatistics.cpp:
(WebKit::NetworkCache::Statistics::bootstrapFromNetworkCache):
(WebKit::NetworkCache::Statistics::recordNotUsingCacheForRequest):
(WebKit::NetworkCache::Statistics::recordRetrievalFailure):
(WebKit::NetworkCache::Statistics::writeTimerFired):
(WebKit::NetworkCache::Statistics::addHashesToDatabase):
(WebKit::NetworkCache::Statistics::addStoreDecisionsToDatabase):
* NetworkProcess/cache/NetworkCacheStatistics.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (201394 => 201395)


--- trunk/Source/WebKit2/ChangeLog	2016-05-25 19:08:02 UTC (rev 201394)
+++ trunk/Source/WebKit2/ChangeLog	2016-05-25 19:17:57 UTC (rev 201395)
@@ -1,3 +1,27 @@
+2016-05-25  Chris Dumez  <[email protected]>
+
+        Simplify a few lambda captures in the network cache code
+        https://bugs.webkit.org/show_bug.cgi?id=158076
+
+        Reviewed by Antti Koivisto.
+
+        Simplify a few lambda captures in the network cache code by WTFMoving
+        upon capture.
+
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
+        (WebKit::NetworkCache::SpeculativeLoadManager::retrieve):
+        (WebKit::NetworkCache::SpeculativeLoadManager::retrieveEntryFromStorage):
+        (WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h:
+        * NetworkProcess/cache/NetworkCacheStatistics.cpp:
+        (WebKit::NetworkCache::Statistics::bootstrapFromNetworkCache):
+        (WebKit::NetworkCache::Statistics::recordNotUsingCacheForRequest):
+        (WebKit::NetworkCache::Statistics::recordRetrievalFailure):
+        (WebKit::NetworkCache::Statistics::writeTimerFired):
+        (WebKit::NetworkCache::Statistics::addHashesToDatabase):
+        (WebKit::NetworkCache::Statistics::addStoreDecisionsToDatabase):
+        * NetworkProcess/cache/NetworkCacheStatistics.h:
+
 2016-05-25  Fujii Hironori  <[email protected]>
 
         [Unix] Potential buffer overrun of m_fileDescriptors in readBytesFromSocket of ConnectionUnix.cpp

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp (201394 => 201395)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp	2016-05-25 19:08:02 UTC (rev 201394)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp	2016-05-25 19:17:57 UTC (rev 201395)
@@ -311,7 +311,7 @@
     return requestsHeadersMatch(load.originalRequest(), actualRequest);
 }
 
-bool SpeculativeLoadManager::retrieve(const GlobalFrameID& frameID, const Key& storageKey, const WebCore::ResourceRequest& request, const RetrieveCompletionHandler& completionHandler)
+bool SpeculativeLoadManager::retrieve(const GlobalFrameID& frameID, const Key& storageKey, const WebCore::ResourceRequest& request, RetrieveCompletionHandler&& completionHandler)
 {
     // Check already preloaded entries.
     if (auto preloadedEntry = m_preloadedEntries.take(storageKey)) {
@@ -348,10 +348,8 @@
     LOG(NetworkCacheSpeculativePreloading, "(NetworkProcess) Retrieval: revalidation already in progress for '%s':", storageKey.identifier().utf8().data());
 
     // FIXME: This breaks incremental loading when the revalidation is not successful.
-    auto addResult = m_pendingRetrieveRequests.add(storageKey, nullptr);
-    if (addResult.isNewEntry)
-        addResult.iterator->value = std::make_unique<Vector<RetrieveCompletionHandler>>();
-    addResult.iterator->value->append(completionHandler);
+    auto addResult = m_pendingRetrieveRequests.ensure(storageKey, [] { return std::make_unique<Vector<RetrieveCompletionHandler>>(); });
+    addResult.iterator->value->append(WTFMove(completionHandler));
     return true;
 }
 
@@ -407,9 +405,9 @@
     }));
 }
 
-void SpeculativeLoadManager::retrieveEntryFromStorage(const Key& key, const RetrieveCompletionHandler& completionHandler)
+void SpeculativeLoadManager::retrieveEntryFromStorage(const Key& key, RetrieveCompletionHandler&& completionHandler)
 {
-    m_storage.retrieve(key, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler](auto record) {
+    m_storage.retrieve(key, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler = WTFMove(completionHandler)](auto record) {
         if (!record) {
             completionHandler(nullptr);
             return false;
@@ -530,11 +528,11 @@
     }
 }
 
-void SpeculativeLoadManager::retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)> completionHandler)
+void SpeculativeLoadManager::retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)>&& completionHandler)
 {
     ASSERT(storageKey.type() == "resource");
     auto subresourcesStorageKey = makeSubresourcesKey(storageKey);
-    m_storage.retrieve(subresourcesStorageKey, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler](auto record) {
+    m_storage.retrieve(subresourcesStorageKey, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler = WTFMove(completionHandler)](auto record) {
         if (!record) {
             completionHandler(nullptr);
             return false;

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h (201394 => 201395)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h	2016-05-25 19:08:02 UTC (rev 201394)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h	2016-05-25 19:17:57 UTC (rev 201395)
@@ -52,17 +52,17 @@
     void registerLoad(const GlobalFrameID&, const WebCore::ResourceRequest&, const Key& resourceKey);
 
     typedef std::function<void (std::unique_ptr<Entry>)> RetrieveCompletionHandler;
-    bool retrieve(const GlobalFrameID&, const Key& storageKey, const WebCore::ResourceRequest&, const RetrieveCompletionHandler&);
+    bool retrieve(const GlobalFrameID&, const Key& storageKey, const WebCore::ResourceRequest&, RetrieveCompletionHandler&&);
 
 private:
     class PreloadedEntry;
 
     void addPreloadedEntry(std::unique_ptr<Entry>, const GlobalFrameID&, Optional<WebCore::ResourceRequest>&& revalidationRequest = Nullopt);
     void preloadEntry(const Key&, const SubresourceInfo&, const GlobalFrameID&);
-    void retrieveEntryFromStorage(const Key&, const RetrieveCompletionHandler&);
+    void retrieveEntryFromStorage(const Key&, RetrieveCompletionHandler&&);
     void revalidateEntry(std::unique_ptr<Entry>, const SubresourceInfo&, const GlobalFrameID&);
     bool satisfyPendingRequests(const Key&, Entry*);
-    void retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)>);
+    void retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)>&&);
     void startSpeculativeRevalidation(const GlobalFrameID&, SubresourcesEntry&);
 
     static bool canUsePreloadedEntry(const PreloadedEntry&, const WebCore::ResourceRequest& actualRequest);

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp (201394 => 201395)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp	2016-05-25 19:08:02 UTC (rev 201394)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp	2016-05-25 19:17:57 UTC (rev 201395)
@@ -143,7 +143,7 @@
 
     LOG(NetworkCache, "(NetworkProcess) Bootstrapping the network cache statistics database from the network cache...");
 
-    Vector<StringCapture> hashes;
+    HashSet<String> hashes;
     traverseRecordsFiles(networkCachePath, ASCIILiteral("resource"), [&hashes](const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath) {
         if (isBodyBlob)
             return;
@@ -152,7 +152,7 @@
         if (!Key::stringToHash(hashString, hash))
             return;
 
-        hashes.append(hashString);
+        hashes.add(hashString);
     });
 
     WebCore::SQLiteTransactionInProgressAutoCounter transactionCounter;
@@ -219,9 +219,8 @@
 {
     ASSERT(retrieveDecision != RetrieveDecision::Yes);
 
-    String hash = key.hashAsString();
-    WebCore::URL requestURL = request.url();
-    queryWasEverRequested(hash, NeedUncachedReason::No, [this, hash, requestURL, webPageID, retrieveDecision](bool wasEverRequested, const Optional<StoreDecision>&) {
+    auto hash = key.hashAsString();
+    queryWasEverRequested(hash, NeedUncachedReason::No, [this, hash, requestURL = request.url(), webPageID, retrieveDecision](bool wasEverRequested, const Optional<StoreDecision>&) {
         if (wasEverRequested) {
             String diagnosticKey = retrieveDecisionToDiagnosticKey(retrieveDecision);
             LOG(NetworkCache, "(NetworkProcess) webPageID %" PRIu64 ": %s was previously requested but we are not using the cache, reason: %s", webPageID, requestURL.string().ascii().data(), diagnosticKey.utf8().data());
@@ -260,9 +259,8 @@
 
 void Statistics::recordRetrievalFailure(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request)
 {
-    String hash = key.hashAsString();
-    WebCore::URL requestURL = request.url();
-    queryWasEverRequested(hash, NeedUncachedReason::Yes, [this, hash, requestURL, webPageID](bool wasPreviouslyRequested, const Optional<StoreDecision>& storeDecision) {
+    auto hash = key.hashAsString();
+    queryWasEverRequested(hash, NeedUncachedReason::Yes, [this, hash, requestURL = request.url(), webPageID](bool wasPreviouslyRequested, const Optional<StoreDecision>& storeDecision) {
         if (wasPreviouslyRequested) {
             String diagnosticKey = storeDecisionToDiagnosticKey(storeDecision.value());
             LOG(NetworkCache, "(NetworkProcess) webPageID %" PRIu64 ": %s was previously request but is not in the cache, reason: %s", webPageID, requestURL.string().ascii().data(), diagnosticKey.utf8().data());
@@ -333,17 +331,7 @@
 {
     ASSERT(RunLoop::isMain());
 
-    Vector<StringCapture> hashesToAdd;
-    copyToVector(m_hashesToAdd, hashesToAdd);
-    m_hashesToAdd.clear();
-
-    Vector<std::pair<StringCapture, StoreDecision>> storeDecisionsToAdd;
-    copyToVector(m_storeDecisionsToAdd, storeDecisionsToAdd);
-    m_storeDecisionsToAdd.clear();
-
-    shrinkIfNeeded();
-
-    serialBackgroundIOQueue().dispatch([this, hashesToAdd, storeDecisionsToAdd] {
+    serialBackgroundIOQueue().dispatch([this, hashesToAdd = WTFMove(m_hashesToAdd), storeDecisionsToAdd = WTFMove(m_storeDecisionsToAdd)] {
         if (!m_database.isOpen())
             return;
 
@@ -356,6 +344,8 @@
 
         writeTransaction.commit();
     });
+
+    shrinkIfNeeded();
 }
 
 void Statistics::queryWasEverRequested(const String& hash, NeedUncachedReason needUncachedReason, const RequestedCompletionHandler& completionHandler)
@@ -422,7 +412,7 @@
     });
 }
 
-void Statistics::addHashesToDatabase(const Vector<StringCapture>& hashes)
+void Statistics::addHashesToDatabase(const HashSet<String>& hashes)
 {
     ASSERT(!RunLoop::isMain());
     ASSERT(WebCore::SQLiteDatabaseTracker::hasTransactionInProgress());
@@ -433,14 +423,14 @@
         return;
 
     for (auto& hash : hashes) {
-        statement.bindText(1, hash.string());
+        statement.bindText(1, hash);
         if (executeSQLStatement(statement))
             ++m_approximateEntryCount;
         statement.reset();
     }
 }
 
-void Statistics::addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, StoreDecision>>& storeDecisions)
+void Statistics::addStoreDecisionsToDatabase(const HashMap<String, NetworkCache::StoreDecision>& storeDecisions)
 {
     ASSERT(!RunLoop::isMain());
     ASSERT(WebCore::SQLiteDatabaseTracker::hasTransactionInProgress());
@@ -451,8 +441,8 @@
         return;
 
     for (auto& pair : storeDecisions) {
-        statement.bindText(1, pair.first.string());
-        statement.bindInt(2, static_cast<int>(pair.second));
+        statement.bindText(1, pair.key);
+        statement.bindInt(2, static_cast<int>(pair.value));
         executeSQLStatement(statement);
         statement.reset();
     }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h (201394 => 201395)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h	2016-05-25 19:08:02 UTC (rev 201394)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h	2016-05-25 19:17:57 UTC (rev 201395)
@@ -62,8 +62,8 @@
     void bootstrapFromNetworkCache(const String& networkCachePath);
     void shrinkIfNeeded();
 
-    void addHashesToDatabase(const Vector<StringCapture>& hashes);
-    void addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, NetworkCache::StoreDecision>>&);
+    void addHashesToDatabase(const HashSet<String>& hashes);
+    void addStoreDecisionsToDatabase(const HashMap<String, NetworkCache::StoreDecision>&);
     void writeTimerFired();
 
     typedef std::function<void (bool wasEverRequested, const Optional<StoreDecision>&)> RequestedCompletionHandler;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to