diff options
author | Stefan Kost <ensonic@users.sf.net> | 2010-10-19 14:27:20 +0300 |
---|---|---|
committer | Stefan Kost <ensonic@users.sf.net> | 2010-12-03 09:50:31 +0200 |
commit | 1c50dcd54fb1cd07988b5d928bea9840f80a603c (patch) | |
tree | fabaca898d3272ddaa940fe40b9c20b6c4acc533 | |
parent | aa440a1e247f0f2a9aaa39832323cbc63da5503c (diff) |
gstobject: more default name generation more efficient
Save ~2000 malloc/memcpy/free pairs at startup by running to_lower in-place.
Also skip the numbers as we can.
-rw-r--r-- | gst/gstobject.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/gst/gstobject.c b/gst/gstobject.c index 02e7b4526..5424eb4df 100644 --- a/gst/gstobject.c +++ b/gst/gstobject.c @@ -617,8 +617,9 @@ gst_object_set_name_default (GstObject * object) { const gchar *type_name; gint count; - gchar *name, *tmp; + gchar *name; GQuark q; + guint i, l; /* to ensure guaranteed uniqueness across threads, only one thread * may ever assign a name */ @@ -634,17 +635,20 @@ gst_object_set_name_default (GstObject * object) G_UNLOCK (object_name_mutex); - /* GstFooSink -> foosinkN */ + /* GstFooSink -> foosink<N> */ type_name = g_quark_to_string (q); if (strncmp (type_name, "Gst", 3) == 0) type_name += 3; - tmp = g_strdup_printf ("%s%d", type_name, count); - name = g_ascii_strdown (tmp, -1); - g_free (tmp); + l = strlen (type_name); + name = g_malloc (l + 6 + 1); + for (i = 0; i < l; i++) + name[i] = g_ascii_tolower (type_name[i]); + snprintf (&name[i], 6, "%d", count); GST_OBJECT_LOCK (object); if (G_UNLIKELY (object->parent != NULL)) goto had_parent; + g_free (object->name); object->name = name; |