This enables us to get rid of all the global variables.
I used the opportunity to update function names where call sites where
affected to move scour a step towards a more pythonic style in
general.
Signed-off-by: Niels Thykier <niels@thykier.net>
Both `mergeSiblingGroupsWithCommonAttributes` and `removeNestedGroups`
used the same code in different forms. Extract it into its own
function.
Signed-off-by: Niels Thykier <niels@thykier.net>
Preserve prefix of attribute names when copying them over to the new
node. This fixes an unintentional rewrite of `xml:space` to `space`
that also caused scour to strip whitespace that should have been
preserved.
Closes: #239
Signed-off-by: Niels Thykier <niels@thykier.net>
This avoids calling `findReferencedElements` more than once per
removeDuplicateGradients. This is good for performance as
`findReferencedElements` is one of the slowest functions in scour.
Signed-off-by: Niels Thykier <niels@thykier.net>
Except for one caller, nothing cares what kind of collection is used.
By migrating to a set, we can enable a future rewrite.
Signed-off-by: Niels Thykier <niels@thykier.net>
Regex compilation is by far the most expensive part of
removeDuplicateGradients. This commit reduces the pain a bit by
trading "many small regexes" to "few larger regexes", which avoid some
of the compilation overhead.
Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is mostly to enable the following commit to make
improvements. It does reduce the number of duplicate getAttribute
calls by a tiny bit but it is unlikely to matter in practice.
Signed-off-by: Niels Thykier <niels@thykier.net>
_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>
The `removeUnusedDefs` function can take `referencedIDs` as parameter
and its work do not invalidate it. By moving it up in
`removeUnreferencedElements` we can save a call to
`findReferencedElements` per call to `removeUnreferencedElements`.
Signed-off-by: Niels Thykier <niels@thykier.net>