From 24a9afce475c93a7443f0888878b4425f30ae8a5 Mon Sep 17 00:00:00 2001 From: Florian Eder Date: Sun, 12 Jan 2025 16:05:39 +0000 Subject: [PATCH] create auxillary function to refactor while loop The existing logic was quite hard to read - to make future maintenance easier, the logic is broken up a bit to use explicit variable names, bundled in a single auxillary function --- benchexec/resources.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/benchexec/resources.py b/benchexec/resources.py index d6f99bdcd..efe06ea1c 100644 --- a/benchexec/resources.py +++ b/benchexec/resources.py @@ -428,14 +428,17 @@ def calculate_chosen_level( @return: calculated chosen level as index """ + def next_level_suitable(chosen_level, hierarchy_levels, core_limit): + """Check if its possible to proceed to the next hierarchy level.""" + if chosen_level >= len(hierarchy_levels) - 1: + return False # Already at the last level + current_level_values = next(iter(hierarchy_levels[chosen_level].values())) + return len(current_level_values) < core_limit + chosen_level = 1 # move up in hierarchy as long as the number of cores at the current level is smaller than the coreLimit # if the number of cores at the current level is as big as the coreLimit: exit loop - while ( - chosen_level < len(hierarchy_levels) - 1 - and len(next(iter(hierarchy_levels[chosen_level].values()))) - < coreLimit_rounded_up - ): + while next_level_suitable(chosen_level, hierarchy_levels, coreLimit_rounded_up): chosen_level = chosen_level + 1 return chosen_level