Refactor output.xml flattening code.
Add higher level `if/else` to have separate code paths for start and
end events. Code gets simpler and due to conditions not being
evaluated unnecessarily there's a smallish performance boos as well.
Done after fixing
@@ -154,7 +154,8 @@ class ExecutionResultBuilder:
tag = elem.tag
start = event == 'start'
end = not start
- if start and tag in containers:
+ if start:
+ if tag in containers:
inside_kw += 1
if started >= 0:
started += 1
@@ -165,19 +166,20 @@ class ExecutionResultBuilder:
started = 0
seen_doc = False
tags = []
- elif end and by_tags and inside_kw and started < 0 and tag == 'tag':
- tags.append(elem.text or '')
- if tags_match(tags):
- started = 0
- seen_doc = False
- if end and tag in containers:
+ else:
+ if tag in containers:
inside_kw -= 1
if started == 0 and not seen_doc:
doc = ET.Element('doc')
doc.text = '_*Keyword content flattened.*_'
yield 'start', doc
yield 'end', doc
- if started == 0 and end and tag == 'doc':
+ elif by_tags and inside_kw and started < 0 and tag == 'tag':
+ tags.append(elem.text or '')
+ if tags_match(tags):
+ started = 0
+ seen_doc = False
+ elif started == 0 and tag == 'doc':
seen_doc = True
elem.text = ('%s\n\n_*Keyword content flattened.*_'
% (elem.text or '')).strip()
