Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: Source/core/fetch/Resource.cpp

Issue 645513003: Use C++11 range-based loop in core/fetch (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: mike's comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/fetch/Resource.cpp
diff --git a/Source/core/fetch/Resource.cpp b/Source/core/fetch/Resource.cpp
index 92c8f3671b2e3d25128c6255c1432327b77cc627..df69fb7535ed226adf0bf95ce4c42e734d286dbf 100644
--- a/Source/core/fetch/Resource.cpp
+++ b/Source/core/fetch/Resource.cpp
@@ -623,9 +623,7 @@ void Resource::finishPendingClients()
Vector<ResourceClient*> clientsToNotify;
copyToVector(m_clientsAwaitingCallback, clientsToNotify);
- for (size_t i = 0; i < clientsToNotify.size(); ++i) {
- ResourceClient* client = clientsToNotify[i];
-
+ for (const auto& client : clientsToNotify) {
// Handle case (2) to skip removed clients.
if (!m_clientsAwaitingCallback.remove(client))
continue;
@@ -695,9 +693,7 @@ void Resource::switchClientsToRevalidatedResource()
m_resourceToRevalidate->m_identifier = m_identifier;
m_switchingClientsToRevalidatedResource = true;
- HashSet<ResourcePtrBase*>::iterator end = m_handlesToRevalidate.end();
- for (HashSet<ResourcePtrBase*>::iterator it = m_handlesToRevalidate.begin(); it != end; ++it) {
- ResourcePtrBase* handle = *it;
+ for (const auto& handle : m_handlesToRevalidate) {
handle->m_resource = m_resourceToRevalidate;
m_resourceToRevalidate->registerHandle(handle);
--m_handleCount;
@@ -706,12 +702,10 @@ void Resource::switchClientsToRevalidatedResource()
m_handlesToRevalidate.clear();
Vector<ResourceClient*> clientsToMove;
- HashCountedSet<ResourceClient*>::iterator end2 = m_clients.end();
- for (HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); it != end2; ++it) {
- ResourceClient* client = it->key;
- unsigned count = it->value;
+ for (const auto& clientHash : m_clients) {
+ unsigned count = clientHash.value;
while (count) {
- clientsToMove.append(client);
+ clientsToMove.append(clientHash.key);
--count;
}
}
@@ -741,16 +735,15 @@ void Resource::updateResponseAfterRevalidation(const ResourceResponse& validatin
// RFC2616 10.3.5
// Update cached headers from the 304 response
const HTTPHeaderMap& newHeaders = validatingResponse.httpHeaderFields();
- HTTPHeaderMap::const_iterator end = newHeaders.end();
- for (HTTPHeaderMap::const_iterator it = newHeaders.begin(); it != end; ++it) {
+ for (const auto& header : newHeaders) {
// Entity headers should not be sent by servers when generating a 304
// response; misconfigured servers send them anyway. We shouldn't allow
// such headers to update the original request. We'll base this on the
// list defined by RFC2616 7.1, with a few additions for extension headers
// we care about.
- if (!shouldUpdateHeaderAfterRevalidation(it->key))
+ if (!shouldUpdateHeaderAfterRevalidation(header.key))
continue;
- m_response.setHTTPHeaderField(it->key, it->value);
+ m_response.setHTTPHeaderField(header.key, header.value);
}
}
@@ -812,10 +805,10 @@ void Resource::unregisterHandle(ResourcePtrBase* h)
bool Resource::canReuseRedirectChain()
{
- for (size_t i = 0; i < m_redirectChain.size(); ++i) {
- if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTimestamp))
+ for (auto& redirect : m_redirectChain) {
+ if (!canUseResponse(redirect.m_redirectResponse, m_responseTimestamp))
return false;
- if (m_redirectChain[i].m_request.cacheControlContainsNoCache() || m_redirectChain[i].m_request.cacheControlContainsNoStore())
+ if (redirect.m_request.cacheControlContainsNoCache() || redirect.m_request.cacheControlContainsNoStore())
return false;
}
return true;
@@ -913,20 +906,19 @@ bool Resource::ResourceCallback::isScheduled(Resource* resource) const
void Resource::ResourceCallback::timerFired(Timer<ResourceCallback>*)
{
- HashSet<Resource*>::iterator end = m_resourcesWithPendingClients.end();
- Vector<ResourcePtr<Resource> > resources;
- for (HashSet<Resource*>::iterator it = m_resourcesWithPendingClients.begin(); it != end; ++it)
- resources.append(*it);
+ Vector<ResourcePtr<Resource>> resources;
+ for (const auto& resource : m_resourcesWithPendingClients)
+ resources.append(resource);
m_resourcesWithPendingClients.clear();
- for (size_t i = 0; i < resources.size(); i++) {
- resources[i]->assertAlive();
- resources[i]->finishPendingClients();
- resources[i]->assertAlive();
+ for (const auto& resource : resources) {
+ resource->assertAlive();
+ resource->finishPendingClients();
+ resource->assertAlive();
}
- for (size_t i = 0; i < resources.size(); i++)
- resources[i]->assertAlive();
+ for (const auto& resource : resources)
+ resource->assertAlive();
}
static const char* initatorTypeNameToString(const AtomicString& initiatorTypeName)

Powered by Google App Engine
This is Rietveld 408576698