From 397ffc55297c8a56b7c25a5f9c3eddd2d78723fe Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Thu, 21 May 2020 12:40:04 +0000 Subject: [PATCH] make_well_formed: Optimize for the common case of nothing needs to be escaped Signed-off-by: Niels Thykier --- scour/scour.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scour/scour.py b/scour/scour.py index 473a2ed..18a81d2 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3413,6 +3413,11 @@ def remapNamespacePrefix(node, oldprefix, newprefix): def make_well_formed(text, quote_dict=None): if quote_dict is None: quote_dict = XML_ENTS_NO_QUOTES + if not any(c in text for c in quote_dict): + # The quote-able characters are quite rare in SVG (they mostly only + # occur in text elements in practice). Therefore it make sense to + # optimize for this common case + return text return ''.join(quote_dict[c] if c in quote_dict else c for c in text)