From c5362743c3d582943ca4d2cc10a6fba8d9d6b3c6 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Mon, 18 May 2020 21:04:20 +0000 Subject: [PATCH] _getStyle: Avoid calling getAttribute twice for no reason _getStyle accounted for ~8.9% (~17700) of all calls to getAttribute on devices/hidef/secure-card.svgz file from the Oxygen icon theme. This commit removes this part of the dead weight. Signed-off-by: Niels Thykier --- scour/scour.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index c9eff0e..1bb4980 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1610,9 +1610,12 @@ def removeDuplicateGradients(doc): def _getStyle(node): u"""Returns the style attribute of a node as a dictionary.""" - if node.nodeType == Node.ELEMENT_NODE and len(node.getAttribute('style')) > 0: + if node.nodeType != Node.ELEMENT_NODE: + return {} + style_attribute = node.getAttribute('style') + if style_attribute: styleMap = {} - rawStyles = node.getAttribute('style').split(';') + rawStyles = style_attribute.split(';') for style in rawStyles: propval = style.split(':') if len(propval) == 2: