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 <niels@thykier.net>
This commit is contained in:
parent
6ea126d290
commit
58ae54021d
1 changed files with 14 additions and 0 deletions
|
|
@ -1876,6 +1876,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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue