core: set buffer name, short name and title only if the value has changed

This fix reduces the number of messages "_buffer_title_changed" sent to the
weechat relay clients in IRC private buffers (this message was sent for every
new message received in the private buffer).
v2.8-utf8proc
Sébastien Helleu 2019-11-17 21:48:17 +01:00
parent 9a40aa04f8
commit 8cde654c6f
2 changed files with 27 additions and 1 deletions

View File

@ -39,6 +39,7 @@ New features::
Bug fixes::
* core: set buffer name, short name and title only if the value has changed
* core: fix scrolling up in bare mode when switched to bare mode at the top of the buffer (issue #899, issue #978)
* core: optimize load of configuration files
* core: fix window separators not respecting window splits (issue #630)
@ -50,6 +51,7 @@ Bug fixes::
* irc: use path from option xfer.file.upload_path to complete filename in command "/dcc send" (issue #60)
* logger: fix write in log file if it has been deleted or renamed (issue #123)
* python: send "bytes" instead of "str" to callbacks in Python 3 when the string is not UTF-8 valid (issue #1389)
* relay: send message "_buffer_title_changed" to clients only when the title is changed
* xfer: fix memory leak when a xfer is freed and when the plugin is unloaded
Tests::

View File

@ -1294,6 +1294,10 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, const char *name)
if (!buffer || !name || !name[0])
return;
/* same name? */
if (buffer->name && (strcmp (buffer->name, name) == 0))
return;
if (buffer->name)
free (buffer->name);
buffer->name = strdup (name);
@ -1315,6 +1319,14 @@ gui_buffer_set_short_name (struct t_gui_buffer *buffer, const char *short_name)
if (!buffer)
return;
/* same short name? */
if ((!buffer->short_name && !short_name)
|| (buffer->short_name && short_name
&& (strcmp (buffer->short_name, short_name) == 0)))
{
return;
}
if (buffer->short_name)
{
free (buffer->short_name);
@ -1338,7 +1350,11 @@ gui_buffer_set_short_name (struct t_gui_buffer *buffer, const char *short_name)
void
gui_buffer_set_type (struct t_gui_buffer *buffer, enum t_gui_buffer_type type)
{
if (!buffer || (buffer->type == type))
if (!buffer)
return;
/* same type? */
if (buffer->type == type)
return;
gui_line_free_all (buffer);
@ -1363,6 +1379,14 @@ gui_buffer_set_title (struct t_gui_buffer *buffer, const char *new_title)
if (!buffer)
return;
/* same title? */
if ((!buffer->title && !new_title)
|| (buffer->title && new_title
&& (strcmp (buffer->title, new_title) == 0)))
{
return;
}
if (buffer->title)
free (buffer->title);
buffer->title = (new_title && new_title[0]) ? strdup (new_title) : NULL;