mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 13:26:38 +02:00
core: improve speed of nicklist bar item callback
It's faster to use a string with dynamic size, rather than looping on the whole nicklist to compute the length of result string, before looping again to build the string.
This commit is contained in:
@@ -27,6 +27,7 @@ New features::
|
||||
|
||||
Improvements::
|
||||
|
||||
* core: improve speed of nicklist bar item callback
|
||||
* core: allow index for hdata arrays in evaluation of expressions
|
||||
* buflist: display a warning when the script "buffers.pl" is loaded
|
||||
* buflist: add support of char "~" in option buflist.look.sort for case insensitive comparison
|
||||
|
||||
+92
-88
@@ -1670,8 +1670,8 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data,
|
||||
struct t_gui_nick_group *ptr_group;
|
||||
struct t_gui_nick *ptr_nick;
|
||||
struct t_config_option *ptr_option;
|
||||
int i, length;
|
||||
char *str_nicklist;
|
||||
char **nicklist, *str_nicklist;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
@@ -1683,7 +1683,10 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data,
|
||||
if (!buffer)
|
||||
return NULL;
|
||||
|
||||
length = 1;
|
||||
nicklist = string_dyn_alloc (256);
|
||||
if (!nicklist)
|
||||
return NULL;
|
||||
|
||||
ptr_group = NULL;
|
||||
ptr_nick = NULL;
|
||||
gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
|
||||
@@ -1694,108 +1697,109 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data,
|
||||
&& buffer->nicklist_display_groups
|
||||
&& ptr_group->visible))
|
||||
{
|
||||
if (*nicklist[0])
|
||||
string_dyn_concat (nicklist, "\n");
|
||||
|
||||
if (ptr_nick)
|
||||
length += ptr_nick->group->level + 16 /* color */
|
||||
+ ((ptr_nick->prefix) ? strlen (ptr_nick->prefix) : 0)
|
||||
+ 16 /* color */
|
||||
+ strlen (ptr_nick->name) + 1;
|
||||
else
|
||||
length += ptr_group->level - 1
|
||||
+ 16 /* color */
|
||||
+ strlen (gui_nicklist_get_group_start (ptr_group->name))
|
||||
+ 1;
|
||||
}
|
||||
gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
|
||||
}
|
||||
|
||||
str_nicklist = malloc (length);
|
||||
if (str_nicklist)
|
||||
{
|
||||
str_nicklist[0] = '\0';
|
||||
ptr_group = NULL;
|
||||
ptr_nick = NULL;
|
||||
gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
|
||||
while (ptr_group || ptr_nick)
|
||||
{
|
||||
if ((ptr_nick && ptr_nick->visible)
|
||||
|| (ptr_group && !ptr_nick
|
||||
&& buffer->nicklist_display_groups
|
||||
&& ptr_group->visible))
|
||||
{
|
||||
if (str_nicklist[0])
|
||||
strcat (str_nicklist, "\n");
|
||||
|
||||
if (ptr_nick)
|
||||
if (buffer->nicklist_display_groups)
|
||||
{
|
||||
if (buffer->nicklist_display_groups)
|
||||
for (i = 0; i < ptr_nick->group->level; i++)
|
||||
{
|
||||
for (i = 0; i < ptr_nick->group->level; i++)
|
||||
{
|
||||
strcat (str_nicklist, " ");
|
||||
}
|
||||
string_dyn_concat (nicklist, " ");
|
||||
}
|
||||
if (ptr_nick->prefix_color)
|
||||
{
|
||||
if (strchr (ptr_nick->prefix_color, '.'))
|
||||
{
|
||||
config_file_search_with_string (ptr_nick->prefix_color,
|
||||
NULL, NULL, &ptr_option,
|
||||
NULL);
|
||||
if (ptr_option)
|
||||
strcat (str_nicklist, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(ptr_option))));
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat (str_nicklist, gui_color_get_custom (ptr_nick->prefix_color));
|
||||
}
|
||||
}
|
||||
if (ptr_nick->prefix)
|
||||
strcat (str_nicklist, ptr_nick->prefix);
|
||||
if (ptr_nick->color)
|
||||
{
|
||||
if (strchr (ptr_nick->color, '.'))
|
||||
{
|
||||
config_file_search_with_string (ptr_nick->color,
|
||||
NULL, NULL, &ptr_option,
|
||||
NULL);
|
||||
if (ptr_option)
|
||||
strcat (str_nicklist, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(ptr_option))));
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat (str_nicklist, gui_color_get_custom (ptr_nick->color));
|
||||
}
|
||||
}
|
||||
strcat (str_nicklist, ptr_nick->name);
|
||||
}
|
||||
else
|
||||
if (ptr_nick->prefix_color)
|
||||
{
|
||||
for (i = 0; i < ptr_group->level - 1; i++)
|
||||
if (strchr (ptr_nick->prefix_color, '.'))
|
||||
{
|
||||
strcat (str_nicklist, " ");
|
||||
}
|
||||
if (ptr_group->color)
|
||||
{
|
||||
if (strchr (ptr_group->color, '.'))
|
||||
{
|
||||
config_file_search_with_string (ptr_group->color,
|
||||
NULL, NULL, &ptr_option,
|
||||
config_file_search_with_string (ptr_nick->prefix_color,
|
||||
NULL, NULL, &ptr_option,
|
||||
NULL);
|
||||
if (ptr_option)
|
||||
strcat (str_nicklist, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(ptr_option))));
|
||||
}
|
||||
else
|
||||
if (ptr_option)
|
||||
{
|
||||
strcat (str_nicklist, gui_color_get_custom (ptr_group->color));
|
||||
string_dyn_concat (
|
||||
nicklist,
|
||||
gui_color_get_custom (
|
||||
gui_color_get_name (
|
||||
CONFIG_COLOR(ptr_option))));
|
||||
}
|
||||
}
|
||||
strcat (str_nicklist, gui_nicklist_get_group_start (ptr_group->name));
|
||||
else
|
||||
{
|
||||
string_dyn_concat (nicklist,
|
||||
gui_color_get_custom (
|
||||
ptr_nick->prefix_color));
|
||||
}
|
||||
}
|
||||
if (ptr_nick->prefix)
|
||||
string_dyn_concat (nicklist, ptr_nick->prefix);
|
||||
if (ptr_nick->color)
|
||||
{
|
||||
if (strchr (ptr_nick->color, '.'))
|
||||
{
|
||||
config_file_search_with_string (ptr_nick->color,
|
||||
NULL, NULL, &ptr_option,
|
||||
NULL);
|
||||
if (ptr_option)
|
||||
{
|
||||
string_dyn_concat (
|
||||
nicklist,
|
||||
gui_color_get_custom (
|
||||
gui_color_get_name (
|
||||
CONFIG_COLOR(ptr_option))));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string_dyn_concat (nicklist,
|
||||
gui_color_get_custom (
|
||||
ptr_nick->color));
|
||||
}
|
||||
}
|
||||
string_dyn_concat (nicklist, ptr_nick->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < ptr_group->level - 1; i++)
|
||||
{
|
||||
string_dyn_concat (nicklist, " ");
|
||||
}
|
||||
if (ptr_group->color)
|
||||
{
|
||||
if (strchr (ptr_group->color, '.'))
|
||||
{
|
||||
config_file_search_with_string (ptr_group->color,
|
||||
NULL, NULL, &ptr_option,
|
||||
NULL);
|
||||
if (ptr_option)
|
||||
{
|
||||
string_dyn_concat (
|
||||
nicklist,
|
||||
gui_color_get_custom (
|
||||
gui_color_get_name (
|
||||
CONFIG_COLOR(ptr_option))));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string_dyn_concat (nicklist,
|
||||
gui_color_get_custom (
|
||||
ptr_group->color));
|
||||
}
|
||||
}
|
||||
string_dyn_concat (nicklist,
|
||||
gui_nicklist_get_group_start (
|
||||
ptr_group->name));
|
||||
}
|
||||
gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
|
||||
}
|
||||
gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
|
||||
}
|
||||
|
||||
str_nicklist = *nicklist;
|
||||
|
||||
string_dyn_free (nicklist, 0);
|
||||
|
||||
return str_nicklist;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user