mirror of
https://codeberg.org/adnano/wmenu.git
synced 2026-02-07 04:06:47 -05:00
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.
This commit is contained in:
parent
12b8f83be4
commit
260eaba88e
5 changed files with 50 additions and 42 deletions
3
render.c
3
render.c
|
|
@ -28,7 +28,8 @@ void calc_widths(struct menu *menu) {
|
|||
menu->right_arrow = text_width(cairo, menu->font, ">") + 2 * menu->padding;
|
||||
|
||||
// Calculate item widths and input area width
|
||||
for (struct item *item = menu->items; item; item = item->next) {
|
||||
for (size_t i = 0; i < menu->item_count; i++) {
|
||||
struct item *item = &menu->items[i];
|
||||
item->width = text_width(cairo, menu->font, item->text);
|
||||
if (item->width > menu->inputw) {
|
||||
menu->inputw = item->width;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue