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

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

Issue 294393004: Simplify SVGResourcesCycleSolver::resourceContainsCycles (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fold the method; Use pre-order traversal to avoid recursion. Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/svg/custom/pattern-content-cycle-w-resourceless-container-expected.txt ('k') | 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 SVGResourcesCycleSolver::~SVGResourcesCycleSolver() 46 SVGResourcesCycleSolver::~SVGResourcesCycleSolver()
47 { 47 {
48 } 48 }
49 49
50 bool SVGResourcesCycleSolver::resourceContainsCycles(RenderObject* renderer) con st 50 bool SVGResourcesCycleSolver::resourceContainsCycles(RenderObject* renderer) con st
51 { 51 {
52 ASSERT(renderer); 52 ASSERT(renderer);
53 53
54 // First operate on the resources of the given renderer. 54 // First (first loop iteration) operate on the resources of the given
55 // renderer.
55 // <marker id="a"> <path marker-start="url(#b)"/> ... 56 // <marker id="a"> <path marker-start="url(#b)"/> ...
56 // <marker id="b" marker-start="url(#a)"/> 57 // <marker id="b" marker-start="url(#a)"/>
57 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj ect(renderer)) {
58 HashSet<RenderSVGResourceContainer*> resourceSet;
59 resources->buildSetOfResources(resourceSet);
60
61 // Walk all resources and check wheter they reference any resource conta ined in the resources set.
62 HashSet<RenderSVGResourceContainer*>::iterator end = resourceSet.end();
63 for (HashSet<RenderSVGResourceContainer*>::iterator it = resourceSet.beg in(); it != end; ++it) {
64 if (m_allResources.contains(*it))
65 return true;
66 }
67 }
68
69 // Then operate on the child resources of the given renderer. 58 // Then operate on the child resources of the given renderer.
70 // <marker id="a"> <path marker-start="url(#b)"/> ... 59 // <marker id="a"> <path marker-start="url(#b)"/> ...
71 // <marker id="b"> <path marker-start="url(#a)"/> ... 60 // <marker id="b"> <path marker-start="url(#a)"/> ...
72 for (RenderObject* child = renderer->slowFirstChild(); child; child = child- >nextSibling()) { 61 for (RenderObject* child = renderer; child; child = child->nextInPreOrder(re nderer)) {
73 SVGResources* childResources = SVGResourcesCache::cachedResourcesForRend erObject(child); 62 SVGResources* childResources = SVGResourcesCache::cachedResourcesForRend erObject(child);
74 if (!childResources) 63 if (!childResources)
75 continue; 64 continue;
76 65
77 // A child of the given 'resource' contains resources. 66 // A child of the given 'resource' contains resources.
78 HashSet<RenderSVGResourceContainer*> childSet; 67 HashSet<RenderSVGResourceContainer*> childSet;
79 childResources->buildSetOfResources(childSet); 68 childResources->buildSetOfResources(childSet);
80 69
81 // Walk all child resources and check wheter they reference any resource contained in the resources set. 70 // Walk all child resources and check whether they reference any resourc e contained in the resources set.
82 HashSet<RenderSVGResourceContainer*>::iterator end = childSet.end(); 71 HashSet<RenderSVGResourceContainer*>::iterator end = childSet.end();
83 for (HashSet<RenderSVGResourceContainer*>::iterator it = childSet.begin( ); it != end; ++it) { 72 for (HashSet<RenderSVGResourceContainer*>::iterator it = childSet.begin( ); it != end; ++it) {
84 if (m_allResources.contains(*it)) 73 if (m_allResources.contains(*it))
85 return true; 74 return true;
86 } 75 }
87
88 // Walk children recursively, stop immediately if we found a cycle
89 if (resourceContainsCycles(child))
90 return true;
91 } 76 }
92
93 return false; 77 return false;
94 } 78 }
95 79
96 void SVGResourcesCycleSolver::resolveCycles() 80 void SVGResourcesCycleSolver::resolveCycles()
97 { 81 {
98 ASSERT(m_allResources.isEmpty()); 82 ASSERT(m_allResources.isEmpty());
99 83
100 #if DEBUG_CYCLE_DETECTION > 0 84 #if DEBUG_CYCLE_DETECTION > 0
101 fprintf(stderr, "\nBefore cycle detection:\n"); 85 fprintf(stderr, "\nBefore cycle detection:\n");
102 m_resources->dump(m_renderer); 86 m_resources->dump(m_renderer);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 ASSERT(resourceLeadingToCycle == m_resources->clipper()); 183 ASSERT(resourceLeadingToCycle == m_resources->clipper());
200 m_resources->resetClipper(); 184 m_resources->resetClipper();
201 break; 185 break;
202 case SolidColorResourceType: 186 case SolidColorResourceType:
203 ASSERT_NOT_REACHED(); 187 ASSERT_NOT_REACHED();
204 break; 188 break;
205 } 189 }
206 } 190 }
207 191
208 } 192 }
OLDNEW
« no previous file with comments | « LayoutTests/svg/custom/pattern-content-cycle-w-resourceless-container-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698