summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-09-02 15:24:20 +0200
committerSebastien Helleu <flashcode@flashtux.org>2013-09-02 15:24:20 +0200
commit0409faee7faec765148cd8352ae4e2c605fcb6b7 (patch)
tree6e005cde73bfca60818f02d43c2ecb9a70484b6f /src/gui
parent218b2c2df5bd5f740f5858c91966ba8ea660e7f1 (diff)
parenta4f789810a2abe419c5d3b13efab1632f40c6126 (diff)
downloadweechat-0409faee7faec765148cd8352ae4e2c605fcb6b7.zip
Merge branch 'shared-strings'
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-line.c70
-rw-r--r--src/gui/gui-nicklist.c40
2 files changed, 62 insertions, 48 deletions
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index 92bb6f5ef..724d632f8 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -87,6 +87,40 @@ gui_lines_free (struct t_gui_lines *lines)
}
/*
+ * Allocates array with tags in a line_data.
+ */
+
+void
+gui_line_tags_alloc (struct t_gui_line_data *line_data, const char *tags)
+{
+ if (tags)
+ {
+ line_data->tags_array = string_split_shared (tags, ",", 0, 0,
+ &line_data->tags_count);
+ }
+ else
+ {
+ line_data->tags_count = 0;
+ line_data->tags_array = NULL;
+ }
+}
+
+/*
+ * Frees array with tags in a line_data.
+ */
+
+void
+gui_line_tags_free (struct t_gui_line_data *line_data)
+{
+ if (line_data->tags_array)
+ {
+ string_free_split_shared (line_data->tags_array);
+ line_data->tags_count = 0;
+ line_data->tags_array = NULL;
+ }
+}
+
+/*
* Checks if prefix on line is a nick and is the same as nick on previous line.
*
* Returns:
@@ -871,10 +905,9 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer,
{
if (line->data->str_time)
free (line->data->str_time);
- if (line->data->tags_array)
- string_free_split (line->data->tags_array);
+ gui_line_tags_free (line->data);
if (line->data->prefix)
- free (line->data->prefix);
+ string_shared_free (line->data->prefix);
if (line->data->message)
free (line->data->message);
free (line->data);
@@ -1090,19 +1123,10 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date,
new_line->data->date = date;
new_line->data->date_printed = date_printed;
new_line->data->str_time = gui_chat_get_time_string (date);
- if (tags)
- {
- new_line->data->tags_array = string_split (tags, ",", 0, 0,
- &new_line->data->tags_count);
- }
- else
- {
- new_line->data->tags_count = 0;
- new_line->data->tags_array = NULL;
- }
+ gui_line_tags_alloc (new_line->data, tags);
new_line->data->refresh_needed = 0;
new_line->data->prefix = (prefix) ?
- strdup (prefix) : ((date != 0) ? strdup ("") : NULL);
+ (char *)string_shared_get (prefix) : ((date != 0) ? (char *)string_shared_get ("") : NULL);
new_line->data->prefix_length = (prefix) ?
gui_chat_strlen_screen (prefix) : 0;
new_line->data->message = (message) ? strdup (message) : strdup ("");
@@ -1318,8 +1342,8 @@ void
gui_line_clear (struct t_gui_line *line)
{
if (line->data->prefix)
- free (line->data->prefix);
- line->data->prefix = strdup ("");
+ string_shared_free (line->data->prefix);
+ line->data->prefix = (char *)string_shared_get ("");
if (line->data->message)
free (line->data->message);
@@ -1521,18 +1545,8 @@ gui_line_hdata_line_data_update_cb (void *data,
if (hashtable_has_key (hashtable, "tags_array"))
{
value = hashtable_get (hashtable, "tags_array");
- if (line_data->tags_array)
- string_free_split (line_data->tags_array);
- if (value)
- {
- line_data->tags_array = string_split (value, ",", 0, 0,
- &line_data->tags_count);
- }
- else
- {
- line_data->tags_count = 0;
- line_data->tags_array = NULL;
- }
+ gui_line_tags_free (line_data);
+ gui_line_tags_alloc (line_data, value);
rc++;
}
diff --git a/src/gui/gui-nicklist.c b/src/gui/gui-nicklist.c
index e0e21eb77..7c82699e6 100644
--- a/src/gui/gui-nicklist.c
+++ b/src/gui/gui-nicklist.c
@@ -268,8 +268,8 @@ gui_nicklist_add_group (struct t_gui_buffer *buffer,
if (!new_group)
return NULL;
- new_group->name = strdup (name);
- new_group->color = (color) ? strdup (color) : NULL;
+ new_group->name = (char *)string_shared_get (name);
+ new_group->color = (color) ? (char *)string_shared_get (color) : NULL;
new_group->visible = visible;
new_group->parent = (parent_group) ? parent_group : buffer->nicklist_root;
new_group->level = (new_group->parent) ? new_group->parent->level + 1 : 0;
@@ -442,10 +442,10 @@ gui_nicklist_add_nick (struct t_gui_buffer *buffer,
return NULL;
new_nick->group = (group) ? group : buffer->nicklist_root;
- new_nick->name = strdup (name);
- new_nick->color = (color) ? strdup (color) : NULL;
- new_nick->prefix = (prefix) ? strdup (prefix) : NULL;
- new_nick->prefix_color = (prefix_color) ? strdup (prefix_color) : NULL;
+ new_nick->name = (char *)string_shared_get (name);
+ new_nick->color = (color) ? (char *)string_shared_get (color) : NULL;
+ new_nick->prefix = (prefix) ? (char *)string_shared_get (prefix) : NULL;
+ new_nick->prefix_color = (prefix_color) ? (char *)string_shared_get (prefix_color) : NULL;
new_nick->visible = visible;
gui_nicklist_insert_nick_sorted (new_nick->group, new_nick);
@@ -495,13 +495,13 @@ gui_nicklist_remove_nick (struct t_gui_buffer *buffer,
/* free data */
if (nick->name)
- free (nick->name);
+ string_shared_free (nick->name);
if (nick->color)
- free (nick->color);
+ string_shared_free (nick->color);
if (nick->prefix)
- free (nick->prefix);
+ string_shared_free (nick->prefix);
if (nick->prefix_color)
- free (nick->prefix_color);
+ string_shared_free (nick->prefix_color);
buffer->nicklist_count--;
buffer->nicklist_nicks_count--;
@@ -575,9 +575,9 @@ gui_nicklist_remove_group (struct t_gui_buffer *buffer,
/* free data */
if (group->name)
- free (group->name);
+ string_shared_free (group->name);
if (group->color)
- free (group->color);
+ string_shared_free (group->color);
if (group->visible)
{
@@ -884,8 +884,8 @@ gui_nicklist_group_set (struct t_gui_buffer *buffer,
if (string_strcasecmp (property, "color") == 0)
{
if (group->color)
- free (group->color);
- group->color = (value[0]) ? strdup (value) : NULL;
+ string_shared_free (group->color);
+ group->color = (value[0]) ? (char *)string_shared_get (value) : NULL;
group_changed = 1;
}
else if (string_strcasecmp (property, "visible") == 0)
@@ -995,22 +995,22 @@ gui_nicklist_nick_set (struct t_gui_buffer *buffer,
if (string_strcasecmp (property, "color") == 0)
{
if (nick->color)
- free (nick->color);
- nick->color = (value[0]) ? strdup (value) : NULL;
+ string_shared_free (nick->color);
+ nick->color = (value[0]) ? (char *)string_shared_get (value) : NULL;
nick_changed = 1;
}
else if (string_strcasecmp (property, "prefix") == 0)
{
if (nick->prefix)
- free (nick->prefix);
- nick->prefix = (value[0]) ? strdup (value) : NULL;
+ string_shared_free (nick->prefix);
+ nick->prefix = (value[0]) ? (char *)string_shared_get (value) : NULL;
nick_changed = 1;
}
else if (string_strcasecmp (property, "prefix_color") == 0)
{
if (nick->prefix_color)
- free (nick->prefix_color);
- nick->prefix_color = (value[0]) ? strdup (value) : NULL;
+ string_shared_free (nick->prefix_color);
+ nick->prefix_color = (value[0]) ? (char *)string_shared_get (value) : NULL;
nick_changed = 1;
}
else if (string_strcasecmp (property, "visible") == 0)