From 633b381d873fd3043570532f07850b2dff83defc Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 17 Feb 2018 10:59:13 +0000 Subject: [PATCH] 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 --- scour/scour.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index 742658c..813204a 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -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: