make_well_formed: Optimize for the common case of nothing needs to be escaped

Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2020-05-21 12:40:04 +00:00
parent 9656569a72
commit 397ffc5529
No known key found for this signature in database
GPG key ID: A65B78DBE67C7AAC

View file

@ -3413,6 +3413,11 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
def make_well_formed(text, quote_dict=None): def make_well_formed(text, quote_dict=None):
if quote_dict is None: if quote_dict is None:
quote_dict = XML_ENTS_NO_QUOTES 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) return ''.join(quote_dict[c] if c in quote_dict else c for c in text)