From: <tp...@ke...> - 2010-09-16 18:44:04
|
Module: gstreamer Branch: master Commit: 608628d10d17178601a70331fa35715de11212d7 URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=608628d10d17178601a70331fa35715de11212d7 Author: Tim-Philipp Müller <tim...@co...> Date: Thu Sep 16 00:03:38 2010 +0100 structure: micro-optimisation for some setter functions Split out functions that do the actual work, so we avoid doing the same g_return_if_fail() checks multiple times for each call. --- gst/gststructure.c | 115 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 69 insertions(+), 46 deletions(-) diff --git a/gst/gststructure.c b/gst/gststructure.c index daf52b8..5f0ee37 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -417,6 +417,18 @@ gst_structure_set_name (GstStructure * structure, const gchar * name) structure->name = g_quark_from_string (name); } +static inline void +gst_structure_id_set_value_internal (GstStructure * structure, GQuark field, + const GValue * value) +{ + GstStructureField gsfield = { 0, {0,} }; + + gsfield.name = field; + gst_value_init_and_copy (&gsfield.value, value); + + gst_structure_set_field (structure, &gsfield); +} + /** * gst_structure_id_set_value: * @structure: a #GstStructure @@ -431,16 +443,12 @@ void gst_structure_id_set_value (GstStructure * structure, GQuark field, const GValue * value) { - GstStructureField gsfield = { 0, {0,} }; g_return_if_fail (structure != NULL); g_return_if_fail (G_IS_VALUE (value)); g_return_if_fail (IS_MUTABLE (structure)); - gsfield.name = field; - gst_value_init_and_copy (&gsfield.value, value); - - gst_structure_set_field (structure, &gsfield); + gst_structure_id_set_value_internal (structure, field, value); } /** @@ -462,8 +470,8 @@ gst_structure_set_value (GstStructure * structure, g_return_if_fail (G_IS_VALUE (value)); g_return_if_fail (IS_MUTABLE (structure)); - gst_structure_id_set_value (structure, g_quark_from_string (fieldname), - value); + gst_structure_id_set_value_internal (structure, + g_quark_from_string (fieldname), value); } static inline void @@ -533,6 +541,40 @@ gst_structure_take_value (GstStructure * structure, const gchar * fieldname, g_quark_from_string (fieldname), value); } +static void +gst_structure_set_valist_internal (GstStructure * structure, + const gchar * fieldname, va_list varargs) +{ + gchar *err = NULL; + GType type; + + while (fieldname) { + GstStructureField field = { 0 }; + + field.name = g_quark_from_string (fieldname); + + type = va_arg (varargs, GType); + + if (G_UNLIKELY (type == G_TYPE_DATE)) { + g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n"); + type = GST_TYPE_DATE; + } +#if GLIB_CHECK_VERSION(2,23,3) + G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err); +#else + g_value_init (&field.value, type); + G_VALUE_COLLECT (&field.value, varargs, 0, &err); +#endif + if (G_UNLIKELY (err)) { + g_critical ("%s", err); + return; + } + gst_structure_set_field (structure, &field); + + fieldname = va_arg (varargs, gchar *); + } +} + /** * gst_structure_set: * @structure: a #GstStructure @@ -549,9 +591,10 @@ gst_structure_set (GstStructure * structure, const gchar * field, ...) va_list varargs; g_return_if_fail (structure != NULL); + g_return_if_fail (IS_MUTABLE (structure) || field == NULL); va_start (varargs, field); - gst_structure_set_valist (structure, field, varargs); + gst_structure_set_valist_internal (structure, field, varargs); va_end (varargs); } @@ -567,16 +610,23 @@ void gst_structure_set_valist (GstStructure * structure, const gchar * fieldname, va_list varargs) { - gchar *err = NULL; - GType type; - g_return_if_fail (structure != NULL); g_return_if_fail (IS_MUTABLE (structure)); + gst_structure_set_valist_internal (structure, fieldname, varargs); +} + +static void +gst_structure_id_set_valist_internal (GstStructure * structure, + GQuark fieldname, va_list varargs) +{ + gchar *err = NULL; + GType type; + while (fieldname) { GstStructureField field = { 0 }; - field.name = g_quark_from_string (fieldname); + field.name = fieldname; type = va_arg (varargs, GType); @@ -584,11 +634,11 @@ gst_structure_set_valist (GstStructure * structure, g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n"); type = GST_TYPE_DATE; } -#if GLIB_CHECK_VERSION(2,23,3) - G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err); -#else +#ifndef G_VALUE_COLLECT_INIT g_value_init (&field.value, type); G_VALUE_COLLECT (&field.value, varargs, 0, &err); +#else + G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err); #endif if (G_UNLIKELY (err)) { g_critical ("%s", err); @@ -596,7 +646,7 @@ gst_structure_set_valist (GstStructure * structure, } gst_structure_set_field (structure, &field); - fieldname = va_arg (varargs, gchar *); + fieldname = va_arg (varargs, GQuark); } } @@ -622,7 +672,7 @@ gst_structure_id_set (GstStructure * structure, GQuark field, ...) g_return_if_fail (structure != NULL); va_start (varargs, field); - gst_structure_id_set_valist (structure, field, varargs); + gst_structure_id_set_valist_internal (structure, field, varargs); va_end (varargs); } @@ -640,37 +690,10 @@ void gst_structure_id_set_valist (GstStructure * structure, GQuark fieldname, va_list varargs) { - gchar *err = NULL; - GType type; - g_return_if_fail (structure != NULL); g_return_if_fail (IS_MUTABLE (structure)); - while (fieldname) { - GstStructureField field = { 0 }; - - field.name = fieldname; - - type = va_arg (varargs, GType); - - if (G_UNLIKELY (type == G_TYPE_DATE)) { - g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n"); - type = GST_TYPE_DATE; - } -#ifndef G_VALUE_COLLECT_INIT - g_value_init (&field.value, type); - G_VALUE_COLLECT (&field.value, varargs, 0, &err); -#else - G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err); -#endif - if (G_UNLIKELY (err)) { - g_critical ("%s", err); - return; - } - gst_structure_set_field (structure, &field); - - fieldname = va_arg (varargs, GQuark); - } + gst_structure_id_set_valist_internal (structure, fieldname, varargs); } /** @@ -702,7 +725,7 @@ gst_structure_id_new (GQuark name_quark, GQuark field_quark, ...) s = gst_structure_id_empty_new (name_quark); va_start (varargs, field_quark); - gst_structure_id_set_valist (s, field_quark, varargs); + gst_structure_id_set_valist_internal (s, field_quark, varargs); va_end (varargs); return s; |