findReferencedElements: Handle referencingProps separately

Split the handling of referencingProps into a separate loop that calls
findReferencingProperty directly.  This saves a bunch of "make list,
join list, append to another list and eventually split text into two
elements" operations.

This gives approximately 10% faster runtimes on 341 kB flamegraph
generated by the "nytprof" Perl profiler.

Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2018-02-17 10:59:13 +00:00
parent 7249ae8b0a
commit 8543368a6e

View file

@ -593,8 +593,6 @@ def findReferencedElements(node, ids=None):
# now get all style properties and the fill, stroke, filter attributes
styles = node.getAttribute('style').split(';')
for attr in referencingProps:
styles.append(':'.join([attr, node.getAttribute(attr)]))
for style in styles:
propval = style.split(':')
@ -603,6 +601,12 @@ def findReferencedElements(node, ids=None):
val = propval[1].strip()
findReferencingProperty(node, prop, val, ids)
for attr in referencingProps:
val = node.getAttribute(attr).strip()
if not val:
continue
findReferencingProperty(node, attr, val, ids)
if node.hasChildNodes():
for child in node.childNodes:
if child.nodeType == Node.ELEMENT_NODE: