From e4424d83983340d3fa68c494256069b9afc659f6 Mon Sep 17 00:00:00 2001 From: Luiz Amaral Date: Fri, 13 Sep 2024 17:20:01 +0200 Subject: [PATCH] lbpool_states: Use enumerate in for loop This change shaved 26 seconds of the execution time in one of the use-cases. --- src/lbpool_states.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lbpool_states.py b/src/lbpool_states.py index aa66935..4789809 100755 --- a/src/lbpool_states.py +++ b/src/lbpool_states.py @@ -223,12 +223,11 @@ def get_current_states(): ).stdout.splitlines() ret = defaultdict(int) - for line in pfctl_output: - indx = pfctl_output.index(line) + for idx, line in enumerate(pfctl_output): if "route-to" not in line: continue lbpool_name = POOL_RE.search(line).group(1) - last_states = int(STATES_RE.search(pfctl_output[(indx + 1)]).group(1)) + last_states = int(STATES_RE.search(pfctl_output[(idx + 1)]).group(1)) if last_states > ret[lbpool_name]: ret[lbpool_name] = last_states