Skip to content

Commit

Permalink
Split xpath 'or' into two statements for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Vince authored and acabal committed Nov 28, 2023
1 parent cfd4eeb commit ff249ef
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit ff249ef

Please sign in to comment.