From 5cb869bfdf5c5c387a706b54ec22867437f29f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 28 Dec 2007 14:15:53 +0000 Subject: [PATCH] gst/: Bunch of gratuitous nano-optimisations. Original commit message from CVS: * gst/gstcaps.c: (gst_caps_to_string): * gst/gstinfo.c: (gst_debug_construct_term_color): * gst/gstparse.c: (gst_parse_launchv): * gst/gstutils.c: (gst_util_dump_mem): * gst/gstvalue.c: (gst_value_serialize_any_list), (gst_value_transform_any_list_string): Bunch of gratuitous nano-optimisations. --- ChangeLog | 10 ++++++++++ gst/gstcaps.c | 2 +- gst/gstinfo.c | 11 ++++------- gst/gstparse.c | 2 +- gst/gstutils.c | 4 ++-- gst/gstvalue.c | 12 ++++++++---- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2e66ebd2e..a4fe4a9c2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-12-28 Tim-Philipp Müller + + * gst/gstcaps.c: (gst_caps_to_string): + * gst/gstinfo.c: (gst_debug_construct_term_color): + * gst/gstparse.c: (gst_parse_launchv): + * gst/gstutils.c: (gst_util_dump_mem): + * gst/gstvalue.c: (gst_value_serialize_any_list), + (gst_value_transform_any_list_string): + Bunch of gratuitous nano-optimisations. + 2007-12-28 Tim-Philipp Müller * tests/check/generic/sinks.c: (async_done_func), diff --git a/gst/gstcaps.c b/gst/gstcaps.c index a090765a84..ac3545dcd6 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -1799,7 +1799,7 @@ gst_caps_to_string (const GstCaps * caps) if (i > 0) { /* ';' is now added by gst_structure_to_string */ - g_string_append (s, " "); + g_string_append_c (s, ' '); } structure = gst_caps_get_structure (caps, i); diff --git a/gst/gstinfo.c b/gst/gstinfo.c index 0f1c05658d..7dbd1af4e4 100644 --- a/gst/gstinfo.c +++ b/gst/gstinfo.c @@ -573,15 +573,14 @@ gchar * gst_debug_construct_term_color (guint colorinfo) { GString *color; - gchar *ret; color = g_string_new ("\033[00"); if (colorinfo & GST_DEBUG_BOLD) { - g_string_append (color, ";01"); + g_string_append_len (color, ";01", 3); } if (colorinfo & GST_DEBUG_UNDERLINE) { - g_string_append (color, ";04"); + g_string_append_len (color, ";04", 3); } if (colorinfo & GST_DEBUG_FG_MASK) { g_string_append_printf (color, ";3%1d", colorinfo & GST_DEBUG_FG_MASK); @@ -590,11 +589,9 @@ gst_debug_construct_term_color (guint colorinfo) g_string_append_printf (color, ";4%1d", (colorinfo & GST_DEBUG_BG_MASK) >> 4); } - g_string_append (color, "m"); + g_string_append_c (color, 'm'); - ret = color->str; - g_string_free (color, FALSE); - return ret; + return g_string_free (color, FALSE); } /** diff --git a/gst/gstparse.c b/gst/gstparse.c index 041f68ad35..ba6a6f1fbe 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -112,7 +112,7 @@ gst_parse_launchv (const gchar ** argv, GError ** error) tmp = _gst_parse_escape (arg); g_string_append (str, tmp); g_free (tmp); - g_string_append (str, " "); + g_string_append_c (str, ' '); argvp++; } diff --git a/gst/gstutils.c b/gst/gstutils.c index d21adf021e..1b446f919c 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -57,9 +57,9 @@ gst_util_dump_mem (const guchar * mem, guint size) i = j = 0; while (i < size) { if (g_ascii_isprint (mem[i])) - g_string_append_printf (chars, "%c", mem[i]); + g_string_append_c (chars, mem[i]); else - g_string_append_printf (chars, "."); + g_string_append_c (chars, '.'); g_string_append_printf (string, "%02x ", mem[i]); diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 6e4410864a..1314c828a8 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -97,14 +97,16 @@ gst_value_serialize_any_list (const GValue * value, const gchar * begin, GValue *v; gchar *s_val; - s = g_string_new (begin); + /* estimate minimum string length to minimise re-allocs in GString */ + s = g_string_sized_new (2 + (6 * array->len) + 2); + g_string_append (s, begin); for (i = 0; i < array->len; i++) { v = &g_array_index (array, GValue, i); s_val = gst_value_serialize (v); g_string_append (s, s_val); g_free (s_val); if (i < array->len - 1) { - g_string_append (s, ", "); + g_string_append_len (s, ", ", 2); } } g_string_append (s, end); @@ -123,12 +125,14 @@ gst_value_transform_any_list_string (const GValue * src_value, array = src_value->data[0].v_pointer; - s = g_string_new (begin); + /* estimate minimum string length to minimise re-allocs in GString */ + s = g_string_sized_new (2 + (10 * array->len) + 2); + g_string_append (s, begin); for (i = 0; i < array->len; i++) { list_value = &g_array_index (array, GValue, i); if (i != 0) { - g_string_append (s, ", "); + g_string_append_len (s, ", ", 2); } list_s = g_strdup_value_contents (list_value); g_string_append (s, list_s);