1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: optimize sort of hotlist

Entries are not duplicated any more.
This commit is contained in:
Sébastien Helleu
2024-03-16 21:45:31 +01:00
parent 55203680ba
commit e29f496a96
+12 -18
View File
@@ -538,41 +538,35 @@ gui_hotlist_restore_all_buffers ()
}
}
/*
* Resorts hotlist with new sort type.
* Resorts hotlist.
*/
void
gui_hotlist_resort ()
{
struct t_gui_hotlist *new_hotlist, *last_new_hotlist;
struct t_gui_hotlist *ptr_hotlist, *element;
struct t_gui_hotlist *ptr_hotlist, *ptr_next_hotlist;
/* copy and resort hotlist in new linked list */
/* sort is not needed if hotlist has less than 2 entries */
if (!gui_hotlist || !gui_hotlist->next_hotlist)
return;
/* resort hotlist in new linked list */
new_hotlist = NULL;
last_new_hotlist = NULL;
for (ptr_hotlist = gui_hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
ptr_hotlist = gui_hotlist;
while (ptr_hotlist)
{
element = gui_hotlist_dup (ptr_hotlist);
gui_hotlist_add_hotlist (&new_hotlist, &last_new_hotlist, element);
ptr_next_hotlist = ptr_hotlist->next_hotlist;
gui_hotlist_add_hotlist (&new_hotlist, &last_new_hotlist, ptr_hotlist);
ptr_hotlist = ptr_next_hotlist;
}
/* clear whole hotlist */
gui_hotlist_free_all (&gui_hotlist, &last_gui_hotlist);
/* switch to new sorted hotlist */
gui_hotlist = new_hotlist;
last_gui_hotlist = last_new_hotlist;
/* reassign hotlist in buffers */
for (ptr_hotlist = gui_hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
ptr_hotlist->buffer->hotlist = ptr_hotlist;
}
gui_hotlist_changed_signal (NULL);
}