aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-18 19:06:51 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-18 19:06:51 +0200
commit6f91f8131a26c5315a238314fc282a1cdc1d4a7e (patch)
tree89f5e61b001be4ae1bd37388815b7c275044403c
parenta63db9d9784d445befa35cbdf800f926f157b949 (diff)
downloadtdv-6f91f8131a26c5315a238314fc282a1cdc1d4a7e.tar.gz
tdv-6f91f8131a26c5315a238314fc282a1cdc1d4a7e.tar.xz
tdv-6f91f8131a26c5315a238314fc282a1cdc1d4a7e.zip
Microoptimization
It hurts me to see wasted mallocs.
-rw-r--r--src/sdtui.c11
1 files changed, 6 insertions, 5 deletions
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.