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.
This commit is contained in:
Stefan Kost 2010-10-19 14:27:20 +03:00
parent aa440a1e24
commit 1c50dcd54f

View file

@ -617,8 +617,9 @@ gst_object_set_name_default (GstObject * object)
{ {
const gchar *type_name; const gchar *type_name;
gint count; gint count;
gchar *name, *tmp; gchar *name;
GQuark q; GQuark q;
guint i, l;
/* to ensure guaranteed uniqueness across threads, only one thread /* to ensure guaranteed uniqueness across threads, only one thread
* may ever assign a name */ * may ever assign a name */
@ -634,17 +635,20 @@ gst_object_set_name_default (GstObject * object)
G_UNLOCK (object_name_mutex); G_UNLOCK (object_name_mutex);
/* GstFooSink -> foosinkN */ /* GstFooSink -> foosink<N> */
type_name = g_quark_to_string (q); type_name = g_quark_to_string (q);
if (strncmp (type_name, "Gst", 3) == 0) if (strncmp (type_name, "Gst", 3) == 0)
type_name += 3; type_name += 3;
tmp = g_strdup_printf ("%s%d", type_name, count); l = strlen (type_name);
name = g_ascii_strdown (tmp, -1); name = g_malloc (l + 6 + 1);
g_free (tmp); for (i = 0; i < l; i++)
name[i] = g_ascii_tolower (type_name[i]);
snprintf (&name[i], 6, "%d", count);
GST_OBJECT_LOCK (object); GST_OBJECT_LOCK (object);
if (G_UNLIKELY (object->parent != NULL)) if (G_UNLIKELY (object->parent != NULL))
goto had_parent; goto had_parent;
g_free (object->name); g_free (object->name);
object->name = name; object->name = name;