From 02b1fe99261c33a8c775b12c6c61987f0db551b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 24 May 2017 14:59:50 +0200 Subject: [PATCH] buflist: fix slow switch of buffer when there are a lot of buffers opened (closes #998) The function hdata_search (which evaluates a condition for each item in a list) is too slow to search server and channel on each buffer. It is replaced by a manual search in the list (using weechat_hdata_string to get the name), much faster. --- ChangeLog.adoc | 1 + src/plugins/buflist/buflist.c | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 8e5eee899..a34eb312b 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -29,6 +29,7 @@ Improvements:: Bug fixes:: + * buflist: fix slow switch of buffer when there are a lot of buffers opened (issue #998) * buflist: add option "bar" in command /buflist, do not automatically add the "buflist" bar when the option buflist.look.enabled is off (issue #994) * buflist: fix crash on drag & drop of buffers * relay: fix parsing of CAP command arguments in irc protocol (issue #995) diff --git a/src/plugins/buflist/buflist.c b/src/plugins/buflist/buflist.c index 688262d76..46b770946 100644 --- a/src/plugins/buflist/buflist.c +++ b/src/plugins/buflist/buflist.c @@ -71,8 +71,7 @@ buflist_buffer_get_irc_pointers(struct t_gui_buffer *buffer, struct t_irc_server **server, struct t_irc_channel **channel) { - const char *ptr_server_name, *ptr_channel_name; - char str_condition[512]; + const char *ptr_server_name, *ptr_channel_name, *ptr_name; struct t_hdata *hdata_irc_server, *hdata_irc_channel; *server = NULL; @@ -93,15 +92,15 @@ buflist_buffer_get_irc_pointers(struct t_gui_buffer *buffer, return; /* search the server by name in list of servers */ - snprintf (str_condition, sizeof (str_condition), - "${irc_server.name} == %s", - ptr_server_name); *server = weechat_hdata_get_list (hdata_irc_server, "irc_servers"); - *server = weechat_hdata_search (hdata_irc_server, - *server, - str_condition, - 1); + while (*server) + { + ptr_name = weechat_hdata_string (hdata_irc_server, *server, "name"); + if (strcmp (ptr_name, ptr_server_name) == 0) + break; + *server = weechat_hdata_move (hdata_irc_server, *server, 1); + } if (!*server) return; @@ -117,16 +116,16 @@ buflist_buffer_get_irc_pointers(struct t_gui_buffer *buffer, return; /* search the channel by name in list of channels on the server */ - snprintf (str_condition, sizeof (str_condition), - "${irc_channel.name} == %s", - ptr_channel_name); *channel = weechat_hdata_pointer (hdata_irc_server, *server, "channels"); - *channel = weechat_hdata_search (hdata_irc_channel, - *channel, - str_condition, - 1); + while (*channel) + { + ptr_name = weechat_hdata_string (hdata_irc_channel, *channel, "name"); + if (strcmp (ptr_name, ptr_channel_name) == 0) + break; + *channel = weechat_hdata_move (hdata_irc_channel, *channel, 1); + } } /*