From 6f91f8131a26c5315a238314fc282a1cdc1d4a7e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Tue, 18 Oct 2016 19:06:51 +0200 Subject: Microoptimization It hurts me to see wasted mallocs. --- src/sdtui.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sdtui.c b/src/sdtui.c index a3285fe..54faa7c 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -244,11 +244,12 @@ struct application static void view_entry_split_add (GPtrArray *out, const gchar *text) { - gchar **it, **tmp = g_strsplit (text, "\n", -1); - for (it = tmp; *it; it++) - if (**it) - g_ptr_array_add (out, g_strdup (*it)); - g_strfreev (tmp); + const gchar *p = text, *nl; + for (; (nl = strchr (p, '\n')); p = nl + 1) + if (nl != p) + g_ptr_array_add (out, g_strndup (p, nl - p)); + if (*p) + g_ptr_array_add (out, g_strdup (p)); } /// Decomposes a dictionary entry into the format we want. -- cgit v1.2.3-70-g09d2