Microoptimization

It hurts me to see wasted mallocs.
This commit is contained in:
Přemysl Eric Janouch 2016-10-18 19:06:51 +02:00
parent a63db9d978
commit 6f91f8131a
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 6 additions and 5 deletions

View File

@ -244,11 +244,12 @@ struct application
static void static void
view_entry_split_add (GPtrArray *out, const gchar *text) view_entry_split_add (GPtrArray *out, const gchar *text)
{ {
gchar **it, **tmp = g_strsplit (text, "\n", -1); const gchar *p = text, *nl;
for (it = tmp; *it; it++) for (; (nl = strchr (p, '\n')); p = nl + 1)
if (**it) if (nl != p)
g_ptr_array_add (out, g_strdup (*it)); g_ptr_array_add (out, g_strndup (p, nl - p));
g_strfreev (tmp); if (*p)
g_ptr_array_add (out, g_strdup (p));
} }
/// Decomposes a dictionary entry into the format we want. /// Decomposes a dictionary entry into the format we want.