gst/: Bunch of gratuitous nano-optimisations.
authorTim-Philipp Müller <tim@centricular.net>
Fri, 28 Dec 2007 14:15:53 +0000 (14:15 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Fri, 28 Dec 2007 14:15:53 +0000 (14:15 +0000)
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
gst/gstcaps.c
gst/gstinfo.c
gst/gstparse.c
gst/gstutils.c
gst/gstvalue.c

index e2e66eb..a4fe4a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2007-12-28  Tim-Philipp Müller  <tim at centricular dot net>
 
+       * 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  <tim at centricular dot net>
+
        * tests/check/generic/sinks.c: (async_done_func),
          (async_done_eos_func):
          Fix leak in unit test (bus sync handler must unref the message
index a090765..ac3545d 100644 (file)
@@ -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);
index 0f1c056..7dbd1af 100644 (file)
@@ -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);
 }
 
 /**
index 041f68a..ba6a6f1 100644 (file)
@@ -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++;
   }
 
index d21adf0..1b446f9 100644 (file)
@@ -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]);
 
index 6e44108..1314c82 100644 (file)
@@ -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);