diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2016-10-18 19:06:51 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-10-18 19:06:51 +0200 |
commit | 6f91f8131a26c5315a238314fc282a1cdc1d4a7e (patch) | |
tree | 89f5e61b001be4ae1bd37388815b7c275044403c /src | |
parent | a63db9d9784d445befa35cbdf800f926f157b949 (diff) | |
download | tdv-6f91f8131a26c5315a238314fc282a1cdc1d4a7e.tar.gz tdv-6f91f8131a26c5315a238314fc282a1cdc1d4a7e.tar.xz tdv-6f91f8131a26c5315a238314fc282a1cdc1d4a7e.zip |
Microoptimization
It hurts me to see wasted mallocs.
Diffstat (limited to 'src')
-rw-r--r-- | src/sdtui.c | 11 |
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. |