Commit 1c50dcd5 authored by Stefan Kost's avatar Stefan Kost

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.
parent aa440a1e
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment