diff options
| author | Mikael Magnusson <mikachu@gmail.com> | 2014-10-28 02:23:35 +0100 |
|---|---|---|
| committer | Mikael Magnusson <mikachu@gmail.com> | 2014-10-28 04:14:24 +0100 |
| commit | 088524f0169cbc434098f30df6bca992e8a83b01 (patch) | |
| tree | 2af7294963bb6031d4bf02ff76e5b8c18d333754 | |
| parent | 26951b0d4c90fa04b94561c9ff717dc700ba482b (diff) | |
Use GString for appending strings
It can take a very long time to print a _NET_WM_ICON property for firefox with the previous code, several minutes. Fixes bug #6042 and also implements the change for append_string.
| -rw-r--r-- | tools/obxprop/obxprop.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/tools/obxprop/obxprop.c b/tools/obxprop/obxprop.c index 83ff54a1..1f6e3539 100644 --- a/tools/obxprop/obxprop.c +++ b/tools/obxprop/obxprop.c @@ -106,33 +106,30 @@ static gboolean get_all(Display *d, Window win, Atom prop, return ret; } -gchar *append_string(gchar *before, gchar *after, gboolean quote) +GString *append_string(GString *before, gchar *after, gboolean quote) { - gchar *tmp; const gchar *q = quote ? "\"" : ""; if (before) - tmp = g_strdup_printf("%s, %s%s%s", before, q, after, q); + g_string_append_printf(before, ", %s%s%s", q, after, q); else - tmp = g_strdup_printf("%s%s%s", q, after, q); - g_free(before); - return tmp; + g_string_append_printf(before = g_string_new(NULL), "%s%s%s", q, after, q); + return before; } -gchar *append_int(gchar *before, guint after) +GString *append_int(GString *before, guint after) { - gchar *tmp; if (before) - tmp = g_strdup_printf("%s, %u", before, after); + g_string_append_printf(before, ", %u", after); else - tmp = g_strdup_printf("%u", after); - g_free(before); - return tmp; + g_string_append_printf(before = g_string_new(NULL), "%u", after); + return before; } gchar* read_strings(gchar *val, guint n, gboolean utf8) { GSList *strs = NULL, *it; - gchar *ret, *p; + GString *ret; + gchar *p; guint i; p = val; @@ -162,23 +159,27 @@ gchar* read_strings(gchar *val, guint n, gboolean utf8) g_free(strs->data); strs = g_slist_delete_link(strs, strs); } - return ret; + if (ret) + return g_string_free(ret, FALSE); + return NULL; } gchar* read_atoms(Display *d, guchar *val, guint n) { - gchar *ret; + GString *ret; guint i; ret = NULL; for (i = 0; i < n; ++i) ret = append_string(ret, XGetAtomName(d, ((guint32*)val)[i]), FALSE); - return ret; + if (ret) + return g_string_free(ret, FALSE); + return NULL; } gchar* read_numbers(guchar *val, guint n, guint size) { - gchar *ret; + GString *ret; guint i; ret = NULL; @@ -197,7 +198,9 @@ gchar* read_numbers(guchar *val, guint n, guint size) g_assert_not_reached(); /* unhandled size */ } - return ret; + if (ret) + return g_string_free(ret, FALSE); + return NULL; } gboolean read_prop(Display *d, Window w, Atom prop, const gchar **type, gchar **val) |
