From 54bbea3efdedc6987ffdc14ee1696e8449398814 Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 27 Nov 2023 22:36:00 -0600 Subject: [PATCH] Split xpath 'or' into two statements for performance --- se/se_epub_lint.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/se/se_epub_lint.py b/se/se_epub_lint.py index c82c66ea..e97987d5 100644 --- a/se/se_epub_lint.py +++ b/se/se_epub_lint.py @@ -1285,7 +1285,9 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N section_parent_id = dom_section.get_attr("data-parent") - has_header = bool(dom_section.xpath("./*[re:test(name(), '^h[1-6]$')] | .//*[not(re:test(name(), '^(section|article|nav)$'))]//*[re:test(name(), '^h[1-6]$')]")) + has_header = bool(dom_section.xpath("./*[re:test(name(), '^h[1-6]$')]")) + if not has_header: + has_header = bool(dom_section.xpath(".//*[not(re:test(name(), '^(section|article|nav)$'))]//*[re:test(name(), '^h[1-6]$')]")) if not section_parent_id: # We don't have a data-parent, but do we have a direct parent section in the same file as this section?