_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 <niels@thykier.net>
This commit is contained in:
Niels Thykier 2020-05-18 21:04:20 +00:00
parent 5881890e44
commit c5362743c3
No known key found for this signature in database
GPG key ID: A65B78DBE67C7AAC

View file

@ -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: