removeDuplicateGradients: Avoid compiling regex unless we need it

Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2020-05-18 21:00:55 +00:00
parent 985cb58a26
commit ace24df5c3
No known key found for this signature in database
GPG key ID: A65B78DBE67C7AAC

View file

@ -1581,11 +1581,11 @@ def removeDuplicateGradients(doc):
# for each element that referenced the gradient we are going to replace dup_id with master_id # for each element that referenced the gradient we are going to replace dup_id with master_id
dup_id = dupGrad.getAttribute('id') dup_id = dupGrad.getAttribute('id')
funcIRI = re.compile('url\\([\'"]?#' + dup_id + '[\'"]?\\)') # matches url(#a), url('#a') and url("#a")
# With --keep-unreferenced-defs, we can end up with # With --keep-unreferenced-defs, we can end up with
# unreferenced gradients. See GH#156. # unreferenced gradients. See GH#156.
if dup_id in referencedIDs: if dup_id in referencedIDs:
funcIRI = re.compile('url\\([\'"]?#' + dup_id + '[\'"]?\\)') # matches url(#a), url('#a') and url("#a")
for elem in referencedIDs[dup_id]: for elem in referencedIDs[dup_id]:
# find out which attribute referenced the duplicate gradient # find out which attribute referenced the duplicate gradient
for attr in ['fill', 'stroke']: for attr in ['fill', 'stroke']: