Instead, iterate over (a part of) the array twice:
* once to find where the caps start and end
* once only over the lines with caps
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
scripts/group-qemu-caps.py | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
index ec10f24384..49b64c93fc 100755
--- a/scripts/group-qemu-caps.py
+++ b/scripts/group-qemu-caps.py
@@ -29,27 +29,29 @@ import sys
def load_caps_flags(filename, start_regex, end_regex):
capsflags = []
- game_on = False
lines = []
+ start = 0
+ end = 0
with open(filename, "r") as fh:
lines = fh.read().splitlines()
- for line in lines:
- if game_on:
- if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
- continue
- if re.search(r'''^\s*$''', line):
- continue
- match = re.search(r'''[ ]+([A-Z0-9_]+)''', line)
-
- if match:
- capsflags.append(match[1])
-
+ for idx, line in enumerate(lines):
if re.search(start_regex, line):
- game_on = True
- elif game_on and re.search(end_regex, line):
- game_on = False
+ start = idx
+ elif re.search(end_regex, line):
+ end = idx
+ break
+
+ for line in lines[start:end]:
+ if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
+ continue
+ if re.search(r'''^\s*$''', line):
+ continue
+ match = re.search(r'''[ ]+([A-Z0-9_]+)''', line)
+
+ if match:
+ capsflags.append(match[1])
return capsflags
--
2.45.2