summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-03-16 21:45:31 +0100
committerSébastien Helleu <flashcode@flashtux.org>2024-03-16 22:25:51 +0100
commite29f496a96e63c576c46ebe23fde1b8ac25d16b5 (patch)
tree275db2cebe55270497b414be7a47c136f7012b96 /src/gui
parent55203680bad32c765167551ceb48308016c8b98c (diff)
downloadweechat-e29f496a96e63c576c46ebe23fde1b8ac25d16b5.zip
core: optimize sort of hotlist
Entries are not duplicated any more.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-hotlist.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c
index 8e947d9a0..7964dce94 100644
--- a/src/gui/gui-hotlist.c
+++ b/src/gui/gui-hotlist.c
@@ -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;
+
+ /* sort is not needed if hotlist has less than 2 entries */
+ if (!gui_hotlist || !gui_hotlist->next_hotlist)
+ return;
- /* copy and resort hotlist in new linked list */
+ /* 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);
}