From 62ae9d54153297230c7e4f2ee09c2d338e19de8c Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Tue, 18 Jun 2024 17:41:36 -0400 Subject: [PATCH] Skip regex.sub in get_attr method when attribute is un-namespaced On my local machine this reduces the execution time of `se lint` on Don Quixote from 55 seconds to 40 seconds. Fixes #709 --- se/easy_xml.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/se/easy_xml.py b/se/easy_xml.py index b2d8680e..c6d3eb37 100644 --- a/se/easy_xml.py +++ b/se/easy_xml.py @@ -234,7 +234,9 @@ def _replace_shorthand_namespaces(self, value:str) -> str: epub:type -> {http://www.idpf.org/2007/ops}type """ - if self.namespaces: + # The in check is redundant with the regex but is far more efficient + # when the value is un-namespaced + if ':' in value and self.namespaces: value = regex.sub(r"^(\L):", lambda m: f"{{{self.namespaces[m[1]]}}}", value, ns=self.namespaces.keys()) return value