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

Side by Side Diff: Source/core/rendering/svg/SVGResourcesCache.cpp

Issue 543803005: Using some C++11 goodness to cleanup the iterator code in SVGResourceCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More descriptive variable name. 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 SVGResources* resources = m_cache.set(object, newResources.release()).stored Value->value.get(); 53 SVGResources* resources = m_cache.set(object, newResources.release()).stored Value->value.get();
54 54
55 // Run cycle-detection _afterwards_, so self-references can be caught as wel l. 55 // Run cycle-detection _afterwards_, so self-references can be caught as wel l.
56 SVGResourcesCycleSolver solver(object, resources); 56 SVGResourcesCycleSolver solver(object, resources);
57 solver.resolveCycles(); 57 solver.resolveCycles();
58 58
59 // Walk resources and register the render object at each resources. 59 // Walk resources and register the render object at each resources.
60 HashSet<RenderSVGResourceContainer*> resourceSet; 60 HashSet<RenderSVGResourceContainer*> resourceSet;
61 resources->buildSetOfResources(resourceSet); 61 resources->buildSetOfResources(resourceSet);
62 62
63 HashSet<RenderSVGResourceContainer*>::iterator end = resourceSet.end(); 63 for (auto* resourceContainer : resourceSet)
64 for (HashSet<RenderSVGResourceContainer*>::iterator it = resourceSet.begin() ; it != end; ++it) 64 resourceContainer->addClient(object);
65 (*it)->addClient(object);
66 } 65 }
67 66
68 void SVGResourcesCache::removeResourcesFromRenderObject(RenderObject* object) 67 void SVGResourcesCache::removeResourcesFromRenderObject(RenderObject* object)
69 { 68 {
70 OwnPtr<SVGResources> resources = m_cache.take(object); 69 OwnPtr<SVGResources> resources = m_cache.take(object);
71 if (!resources) 70 if (!resources)
72 return; 71 return;
73 72
74 // Walk resources and register the render object at each resources. 73 // Walk resources and register the render object at each resources.
75 HashSet<RenderSVGResourceContainer*> resourceSet; 74 HashSet<RenderSVGResourceContainer*> resourceSet;
76 resources->buildSetOfResources(resourceSet); 75 resources->buildSetOfResources(resourceSet);
77 76
78 HashSet<RenderSVGResourceContainer*>::iterator end = resourceSet.end(); 77 for (auto* resourceContainer : resourceSet)
79 for (HashSet<RenderSVGResourceContainer*>::iterator it = resourceSet.begin() ; it != end; ++it) 78 resourceContainer->removeClient(object);
80 (*it)->removeClient(object);
81 } 79 }
82 80
83 static inline SVGResourcesCache* resourcesCacheFromRenderObject(const RenderObje ct* renderer) 81 static inline SVGResourcesCache* resourcesCacheFromRenderObject(const RenderObje ct* renderer)
84 { 82 {
85 Document& document = renderer->document(); 83 Document& document = renderer->document();
86 84
87 SVGDocumentExtensions& extensions = document.accessSVGExtensions(); 85 SVGDocumentExtensions& extensions = document.accessSVGExtensions();
88 SVGResourcesCache* cache = extensions.resourcesCache(); 86 SVGResourcesCache* cache = extensions.resourcesCache();
89 ASSERT(cache); 87 ASSERT(cache);
90 88
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 175 }
178 176
179 void SVGResourcesCache::resourceDestroyed(RenderSVGResourceContainer* resource) 177 void SVGResourcesCache::resourceDestroyed(RenderSVGResourceContainer* resource)
180 { 178 {
181 ASSERT(resource); 179 ASSERT(resource);
182 SVGResourcesCache* cache = resourcesCacheFromRenderObject(resource); 180 SVGResourcesCache* cache = resourcesCacheFromRenderObject(resource);
183 181
184 // The resource itself may have clients, that need to be notified. 182 // The resource itself may have clients, that need to be notified.
185 cache->removeResourcesFromRenderObject(resource); 183 cache->removeResourcesFromRenderObject(resource);
186 184
187 CacheMap::iterator end = cache->m_cache.end(); 185 for (auto& objectResources : cache->m_cache) {
188 for (CacheMap::iterator it = cache->m_cache.begin(); it != end; ++it) { 186 objectResources.value->resourceDestroyed(resource);
189 it->value->resourceDestroyed(resource);
190 187
191 // Mark users of destroyed resources as pending resolution based on the id of the old resource. 188 // Mark users of destroyed resources as pending resolution based on the id of the old resource.
192 Element* resourceElement = resource->element(); 189 Element* resourceElement = resource->element();
193 Element* clientElement = toElement(it->key->node()); 190 Element* clientElement = toElement(objectResources.key->node());
194 SVGDocumentExtensions& extensions = clientElement->document().accessSVGE xtensions(); 191 SVGDocumentExtensions& extensions = clientElement->document().accessSVGE xtensions();
195 192
196 extensions.addPendingResource(resourceElement->fastGetAttribute(HTMLName s::idAttr), clientElement); 193 extensions.addPendingResource(resourceElement->fastGetAttribute(HTMLName s::idAttr), clientElement);
197 } 194 }
198 } 195 }
199 196
200 } 197 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698