commit cfd17f57229d73cacfd2f5569768994bc3d4b569
parent 43235c2f160be75e0c22f88c46ed4fcaf54010c3
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 28 Sep 2019 11:58:25 +0200
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.
Diffstat:
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git 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