SVGDocumentExtensions::resourcesCache() should return a reference.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 01:05:01 +0000 (01:05 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 01:05:01 +0000 (01:05 +0000)
<https://webkit.org/b/128087>

The SVGResourcesCache is always present when the Document is using
SVG extensions, so make this return a reference and propagate that
knowledge to the call site.

This gets rid of an assertion and some rickety looking ->'s.
Also converted a loop to use C++11 range for syntax.

Reviewed by Sam Weinig.

* rendering/svg/SVGResourcesCache.cpp:
(WebCore::resourcesCacheFromRenderer):
(WebCore::SVGResourcesCache::cachedResourcesForRenderObject):
(WebCore::SVGResourcesCache::clientStyleChanged):
(WebCore::SVGResourcesCache::clientWasAddedToTree):
(WebCore::SVGResourcesCache::clientWillBeRemovedFromTree):
(WebCore::SVGResourcesCache::clientDestroyed):
(WebCore::SVGResourcesCache::resourceDestroyed):
* svg/SVGDocumentExtensions.h:
(WebCore::SVGDocumentExtensions::resourcesCache):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163277 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/svg/SVGResourcesCache.cpp
Source/WebCore/svg/SVGDocumentExtensions.h

index 3b0ca76c4e120387c7d33e50935d7dd9a405e7f3..d54132c98256739f495cb811e9d29fe8509d6950 100644 (file)
@@ -1,3 +1,28 @@
+2014-02-02  Andreas Kling  <akling@apple.com>
+
+        SVGDocumentExtensions::resourcesCache() should return a reference.
+        <https://webkit.org/b/128087>
+
+        The SVGResourcesCache is always present when the Document is using
+        SVG extensions, so make this return a reference and propagate that
+        knowledge to the call site.
+
+        This gets rid of an assertion and some rickety looking ->'s.
+        Also converted a loop to use C++11 range for syntax.
+
+        Reviewed by Sam Weinig.
+
+        * rendering/svg/SVGResourcesCache.cpp:
+        (WebCore::resourcesCacheFromRenderer):
+        (WebCore::SVGResourcesCache::cachedResourcesForRenderObject):
+        (WebCore::SVGResourcesCache::clientStyleChanged):
+        (WebCore::SVGResourcesCache::clientWasAddedToTree):
+        (WebCore::SVGResourcesCache::clientWillBeRemovedFromTree):
+        (WebCore::SVGResourcesCache::clientDestroyed):
+        (WebCore::SVGResourcesCache::resourceDestroyed):
+        * svg/SVGDocumentExtensions.h:
+        (WebCore::SVGDocumentExtensions::resourcesCache):
+
 2014-02-02  Andreas Kling  <akling@apple.com>
 
         RenderSVGInlineText::computeNewScaledFontForStyle() should take references.
index fad518a32171728f2cace0192bd12a521a627df1..fa40eec27a0a05bd65ebed5f30c960452becf29f 100644 (file)
@@ -76,20 +76,16 @@ void SVGResourcesCache::removeResourcesFromRenderer(RenderElement& renderer)
         (*it)->removeClient(&renderer);
 }
 
-static inline SVGResourcesCache* resourcesCacheFromRenderObject(const RenderObject& renderer)
+static inline SVGResourcesCache& resourcesCacheFromRenderer(const RenderObject& renderer)
 {
     SVGDocumentExtensions* extensions = renderer.document().accessSVGExtensions();
     ASSERT(extensions);
-
-    SVGResourcesCache* cache = extensions->resourcesCache();
-    ASSERT(cache);
-
-    return cache;
+    return extensions->resourcesCache();
 }
 
 SVGResources* SVGResourcesCache::cachedResourcesForRenderObject(const RenderObject& renderer)
 {
-    return resourcesCacheFromRenderObject(renderer)->m_cache.get(&renderer);
+    return resourcesCacheFromRenderer(renderer).m_cache.get(&renderer);
 }
 
 void SVGResourcesCache::clientLayoutChanged(RenderElement& renderer)
@@ -122,9 +118,9 @@ void SVGResourcesCache::clientStyleChanged(RenderElement& renderer, StyleDiffere
     // FIXME: Avoid passing in a useless StyleDifference, but instead compare oldStyle/newStyle to see which resources changed
     // to be able to selectively rebuild individual resources, instead of all of them.
     if (rendererCanHaveResources(renderer)) {
-        SVGResourcesCache* cache = resourcesCacheFromRenderObject(renderer);
-        cache->removeResourcesFromRenderer(renderer);
-        cache->addResourcesFromRenderer(renderer, newStyle);
+        auto& cache = resourcesCacheFromRenderer(renderer);
+        cache.removeResourcesFromRenderer(renderer);
+        cache.addResourcesFromRenderer(renderer, newStyle);
     }
 
     RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer, false);
@@ -143,8 +139,7 @@ void SVGResourcesCache::clientWasAddedToTree(RenderObject& renderer)
     if (!rendererCanHaveResources(renderer))
         return;
     RenderElement& elementRenderer = toRenderElement(renderer);
-    SVGResourcesCache* cache = resourcesCacheFromRenderObject(elementRenderer);
-    cache->addResourcesFromRenderer(elementRenderer, elementRenderer.style());
+    resourcesCacheFromRenderer(elementRenderer).addResourcesFromRenderer(elementRenderer, elementRenderer.style());
 }
 
 void SVGResourcesCache::clientWillBeRemovedFromTree(RenderObject& renderer)
@@ -157,8 +152,7 @@ void SVGResourcesCache::clientWillBeRemovedFromTree(RenderObject& renderer)
     if (!rendererCanHaveResources(renderer))
         return;
     RenderElement& elementRenderer = toRenderElement(renderer);
-    SVGResourcesCache* cache = resourcesCacheFromRenderObject(elementRenderer);
-    cache->removeResourcesFromRenderer(elementRenderer);
+    resourcesCacheFromRenderer(elementRenderer).removeResourcesFromRenderer(elementRenderer);
 }
 
 void SVGResourcesCache::clientDestroyed(RenderElement& renderer)
@@ -167,23 +161,22 @@ void SVGResourcesCache::clientDestroyed(RenderElement& renderer)
     if (resources)
         resources->removeClientFromCache(renderer);
 
-    SVGResourcesCache* cache = resourcesCacheFromRenderObject(renderer);
-    cache->removeResourcesFromRenderer(renderer);
+    resourcesCacheFromRenderer(renderer).removeResourcesFromRenderer(renderer);
 }
 
 void SVGResourcesCache::resourceDestroyed(RenderSVGResourceContainer& resource)
 {
-    SVGResourcesCache* cache = resourcesCacheFromRenderObject(resource);
+    auto& cache = resourcesCacheFromRenderer(resource);
 
     // The resource itself may have clients, that need to be notified.
-    cache->removeResourcesFromRenderer(resource);
+    cache.removeResourcesFromRenderer(resource);
 
-    for (auto it = cache->m_cache.begin(), end = cache->m_cache.end(); it != end; ++it) {
-        it->value->resourceDestroyed(resource);
+    for (auto& it : cache.m_cache) {
+        it.value->resourceDestroyed(resource);
 
         // Mark users of destroyed resources as pending resolution based on the id of the old resource.
         Element& resourceElement = resource.element();
-        Element* clientElement = toElement(it->key->node());
+        Element* clientElement = toElement(it.key->node());
         SVGDocumentExtensions* extensions = clientElement->document().accessSVGExtensions();
 
         extensions->addPendingResource(resourceElement.getIdAttribute(), clientElement);
index 460b145704e0d30c6c3b4a73af7b42ffa19ae96f..052aa453488b38f9def30655321fa57804ca69af 100644 (file)
@@ -62,7 +62,7 @@ public:
     void reportWarning(const String&);
     void reportError(const String&);
 
-    SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); }
+    SVGResourcesCache& resourcesCache() { return *m_resourcesCache; }
 
     HashSet<SVGElement*>* setOfElementsReferencingTarget(SVGElement* referencedElement) const;
     void addElementReferencingTarget(SVGElement* referencingElement, SVGElement* referencedElement);