From f9660feb94696cd08d8ba397077e20a1a9164e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 3 Nov 2024 23:35:13 +0100 Subject: [PATCH] core: fix too many sorts of hotlist when buffers are moved (issue #2097) A performance issue was happening when buffers are moved to another position and when the hotlist contains a lot of buffers: each time a signal "buffer_moved" is sent, the hotlist is sorted again. This fix delays the resort of hotlist after all the moves are done using a timer with a very small delay (one millisecond). --- CHANGELOG.md | 1 + src/gui/gui-bar-item.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f4ab426..d9492b6d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- core: fix too many sorts of hotlist when buffers are moved ([#2097](https://github.com/weechat/weechat/issues/2097)) - relay, xfer: fix letters with actions displayed on top of buffer ## Version 4.4.3 (2024-10-30) diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index e2d81f14c..2e5220e04 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -71,6 +71,7 @@ char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] = }; struct t_gui_bar_item_hook *gui_bar_item_hooks = NULL; struct t_hook *gui_bar_item_timer = NULL; +struct t_hook *gui_bar_item_timer_hotlist_resort = NULL; /* @@ -2275,6 +2276,25 @@ gui_bar_item_timer_cb (const void *pointer, void *data, int remaining_calls) return WEECHAT_RC_OK; } +/* + * Timer callback for resorting hotlist. + */ + +int +gui_bar_item_timer_hotlist_resort_cb (const void *pointer, void *data, + int remaining_calls) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) remaining_calls; + + gui_hotlist_resort (); + + gui_bar_item_timer_hotlist_resort = NULL; + + return WEECHAT_RC_OK; +} /* * Callback when a signal is received: rebuilds an item. */ @@ -2298,7 +2318,13 @@ gui_bar_item_signal_cb (const void *pointer, void *data, if ((strcmp (item, "hotlist") == 0) && (strcmp (signal, "hotlist_changed") != 0)) { - gui_hotlist_resort (); + if (!gui_bar_item_timer_hotlist_resort) + { + gui_bar_item_timer_hotlist_resort = hook_timer ( + NULL, + 1, 0, 1, + &gui_bar_item_timer_hotlist_resort_cb, NULL, NULL); + } } gui_bar_item_update (item); }