From c0c9a9c2c13eb0472cbbe0d7006463966b987bd5 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 17 Feb 2018 17:21:25 +0000 Subject: [PATCH] Remove an unnecessary loop The unprotected_ids function returns all unprotected ids and removeUnreferencedIDs removes all of them that does not appear in the return value of findReferencedElements. On closer observation it turns out that removeUnreferencedIDs cannot cause nodes/IDs to become unprotected nor unreferenced (as it only remove the "id" attribute, not the node). With this in mind, we can just remove the loop and save a call to all of these functions. Signed-off-by: Niels Thykier --- scour/scour.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index 1998482..1c65ccd 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3471,11 +3471,9 @@ def scourString(in_string, options=None): _num_elements_removed += 1 if options.strip_ids: - bContinueLooping = True - while bContinueLooping: - identifiedElements = unprotected_ids(doc, options) - referencedIDs = findReferencedElements(doc.documentElement) - bContinueLooping = (removeUnreferencedIDs(referencedIDs, identifiedElements) > 0) + referencedIDs = findReferencedElements(doc.documentElement) + identifiedElements = unprotected_ids(doc, options) + removeUnreferencedIDs(referencedIDs, identifiedElements) while removeDuplicateGradientStops(doc) > 0: pass