From cfd17f57229d73cacfd2f5569768994bc3d4b569 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 28 Sep 2019 11:58:25 +0200 Subject: [PATCH] tweaks: speed up the counting of the menu entries to be shown Instead of first counting all available entries and then capping it at MAIN_VISIBLE, simply stop counting when MAIN_VISIBLE is reached. --- src/global.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/global.c b/src/global.c index 79a89978..1360fce9 100644 --- a/src/global.c +++ b/src/global.c @@ -431,17 +431,16 @@ int the_code_for(void (*func)(void), int defaultval) /* Return the number of entries that can be shown in the given menu. */ size_t shown_entries_for(int menu) { - funcstruct *item; + funcstruct *item = allfuncs; size_t count = 0; - for (item = allfuncs; item != NULL; item = item->next) + while (count < MAIN_VISIBLE && item != NULL) { if ((item->menus & menu) && first_sc_for(menu, item->func) != NULL) count++; + item = item->next; + } - if (count > MAIN_VISIBLE) - return MAIN_VISIBLE; - else - return count; + return count; } /* Return the shortcut that corresponds to the values of kbinput (the