From 5dc1b7a820b57801fa3db03510aad719c34ce674 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Tue, 10 Apr 2018 05:29:48 +0000 Subject: [PATCH] scour: Make optimized default_attribute data structures There are a lot of "DefaultAttribute"s and for a given tag, most of the "DefaultAttribute"s are not applicable. Therefore, we create two data structures to assist us with only dealing with the attributes that matter. Here there are two cases: * Those that always matter. These go into default_attributes_unrestricted list. * Those that matter only based on the node name. These go into the default_attributes_restricted_by_tag with the node name as key (with the value being a list of matching attributes). In the next commit, we will use those for optimizing the removal of default attributes. Signed-off-by: Niels Thykier --- scour/scour.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scour/scour.py b/scour/scour.py index 7c8d695..23d0574 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1866,6 +1866,20 @@ default_attributes = [ DefaultAttribute('yChannelSelector', 'A', elements='feDisplacementMap') ] +default_attributes_restricted_by_tag = defaultdict(list) +default_attributes_unrestricted = [] + +for attr in default_attributes: + if attr.elements is None: + # Applies to all tags + default_attributes_unrestricted.append(attr) + continue + if type(attr.elements) is str: + default_attributes_restricted_by_tag[attr.elements].append(attr) + else: + for tag in attr.elements: + default_attributes_restricted_by_tag[tag].append(attr) + def taint(taintedSet, taintedAttribute): u"""Adds an attribute to a set of attributes.