From 260eaba88ec8f54fe2bdbe391b18fcd2db70836f Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Thu, 31 Oct 2024 09:23:26 -0400 Subject: Optimize menu sorting Sorting and deduplicating elements after all items have been registered improves the time complexity of constructing the item list from O(n^2) to O(n log n). On a system with about 4000 menu items, this reduces startup time from about 0.21 seconds to 0.13 seconds. --- wmenu-run.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'wmenu-run.c') diff --git a/wmenu-run.c b/wmenu-run.c index dc86b6d..1b7b8c1 100644 --- a/wmenu-run.c +++ b/wmenu-run.c @@ -20,10 +20,11 @@ static void read_items(struct menu *menu) { if (ent->d_name[0] == '.') { continue; } - menu_add_item(menu, strdup(ent->d_name), true); + menu_add_item(menu, strdup(ent->d_name)); } closedir(dir); } + menu_sort_and_deduplicate(menu); free(path); } -- cgit v1.2.3