Skip to content

Commit 24a9afc

Browse files
committed
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
1 parent dcced78 commit 24a9afc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

benchexec/resources.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,17 @@ def calculate_chosen_level(
428428
@return: calculated chosen level as index
429429
"""
430430

431+
def next_level_suitable(chosen_level, hierarchy_levels, core_limit):
432+
"""Check if its possible to proceed to the next hierarchy level."""
433+
if chosen_level >= len(hierarchy_levels) - 1:
434+
return False # Already at the last level
435+
current_level_values = next(iter(hierarchy_levels[chosen_level].values()))
436+
return len(current_level_values) < core_limit
437+
431438
chosen_level = 1
432439
# move up in hierarchy as long as the number of cores at the current level is smaller than the coreLimit
433440
# if the number of cores at the current level is as big as the coreLimit: exit loop
434-
while (
435-
chosen_level < len(hierarchy_levels) - 1
436-
and len(next(iter(hierarchy_levels[chosen_level].values())))
437-
< coreLimit_rounded_up
438-
):
441+
while next_level_suitable(chosen_level, hierarchy_levels, coreLimit_rounded_up):
439442
chosen_level = chosen_level + 1
440443
return chosen_level
441444

0 commit comments

Comments
 (0)