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.
This commit is contained in:
Tim-Philipp Müller 2010-09-16 00:03:38 +01:00
parent 7e5a9580ef
commit 608628d10d

View file

@ -417,6 +417,18 @@ gst_structure_set_name (GstStructure * structure, const gchar * name)
structure->name = g_quark_from_string (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: * gst_structure_id_set_value:
* @structure: a #GstStructure * @structure: a #GstStructure
@ -431,16 +443,12 @@ void
gst_structure_id_set_value (GstStructure * structure, gst_structure_id_set_value (GstStructure * structure,
GQuark field, const GValue * value) GQuark field, const GValue * value)
{ {
GstStructureField gsfield = { 0, {0,} };
g_return_if_fail (structure != NULL); g_return_if_fail (structure != NULL);
g_return_if_fail (G_IS_VALUE (value)); g_return_if_fail (G_IS_VALUE (value));
g_return_if_fail (IS_MUTABLE (structure)); g_return_if_fail (IS_MUTABLE (structure));
gsfield.name = field; gst_structure_id_set_value_internal (structure, field, value);
gst_value_init_and_copy (&gsfield.value, value);
gst_structure_set_field (structure, &gsfield);
} }
/** /**
@ -462,8 +470,8 @@ gst_structure_set_value (GstStructure * structure,
g_return_if_fail (G_IS_VALUE (value)); g_return_if_fail (G_IS_VALUE (value));
g_return_if_fail (IS_MUTABLE (structure)); g_return_if_fail (IS_MUTABLE (structure));
gst_structure_id_set_value (structure, g_quark_from_string (fieldname), gst_structure_id_set_value_internal (structure,
value); g_quark_from_string (fieldname), value);
} }
static inline void static inline void
@ -533,46 +541,13 @@ gst_structure_take_value (GstStructure * structure, const gchar * fieldname,
g_quark_from_string (fieldname), value); g_quark_from_string (fieldname), value);
} }
/** static void
* gst_structure_set: gst_structure_set_valist_internal (GstStructure * structure,
* @structure: a #GstStructure
* @fieldname: the name of the field to set
* @...: variable arguments
*
* Parses the variable arguments and sets fields accordingly.
* Variable arguments should be in the form field name, field type
* (as a GType), value(s). The last variable argument should be NULL.
*/
void
gst_structure_set (GstStructure * structure, const gchar * field, ...)
{
va_list varargs;
g_return_if_fail (structure != NULL);
va_start (varargs, field);
gst_structure_set_valist (structure, field, varargs);
va_end (varargs);
}
/**
* gst_structure_set_valist:
* @structure: a #GstStructure
* @fieldname: the name of the field to set
* @varargs: variable arguments
*
* va_list form of gst_structure_set().
*/
void
gst_structure_set_valist (GstStructure * structure,
const gchar * fieldname, va_list varargs) const gchar * fieldname, va_list varargs)
{ {
gchar *err = NULL; gchar *err = NULL;
GType type; GType type;
g_return_if_fail (structure != NULL);
g_return_if_fail (IS_MUTABLE (structure));
while (fieldname) { while (fieldname) {
GstStructureField field = { 0 }; GstStructureField field = { 0 };
@ -601,51 +576,53 @@ gst_structure_set_valist (GstStructure * structure,
} }
/** /**
* gst_structure_id_set: * gst_structure_set:
* @structure: a #GstStructure * @structure: a #GstStructure
* @fieldname: the GQuark for the name of the field to set * @fieldname: the name of the field to set
* @...: variable arguments * @...: variable arguments
* *
* Identical to gst_structure_set, except that field names are * Parses the variable arguments and sets fields accordingly.
* passed using the GQuark for the field name. This allows more efficient * Variable arguments should be in the form field name, field type
* setting of the structure if the caller already knows the associated * (as a GType), value(s). The last variable argument should be NULL.
* quark values.
* The last variable argument must be NULL.
*
* Since: 0.10.10
*/ */
void void
gst_structure_id_set (GstStructure * structure, GQuark field, ...) gst_structure_set (GstStructure * structure, const gchar * field, ...)
{ {
va_list varargs; va_list varargs;
g_return_if_fail (structure != NULL); g_return_if_fail (structure != NULL);
g_return_if_fail (IS_MUTABLE (structure) || field == NULL);
va_start (varargs, field); va_start (varargs, field);
gst_structure_id_set_valist (structure, field, varargs); gst_structure_set_valist_internal (structure, field, varargs);
va_end (varargs); va_end (varargs);
} }
/** /**
* gst_structure_id_set_valist: * gst_structure_set_valist:
* @structure: a #GstStructure * @structure: a #GstStructure
* @fieldname: the name of the field to set * @fieldname: the name of the field to set
* @varargs: variable arguments * @varargs: variable arguments
* *
* va_list form of gst_structure_id_set(). * va_list form of gst_structure_set().
*
* Since: 0.10.10
*/ */
void void
gst_structure_id_set_valist (GstStructure * structure, gst_structure_set_valist (GstStructure * structure,
const gchar * fieldname, va_list varargs)
{
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) GQuark fieldname, va_list varargs)
{ {
gchar *err = NULL; gchar *err = NULL;
GType type; GType type;
g_return_if_fail (structure != NULL);
g_return_if_fail (IS_MUTABLE (structure));
while (fieldname) { while (fieldname) {
GstStructureField field = { 0 }; GstStructureField field = { 0 };
@ -673,6 +650,52 @@ gst_structure_id_set_valist (GstStructure * structure,
} }
} }
/**
* gst_structure_id_set:
* @structure: a #GstStructure
* @fieldname: the GQuark for the name of the field to set
* @...: variable arguments
*
* Identical to gst_structure_set, except that field names are
* passed using the GQuark for the field name. This allows more efficient
* setting of the structure if the caller already knows the associated
* quark values.
* The last variable argument must be NULL.
*
* Since: 0.10.10
*/
void
gst_structure_id_set (GstStructure * structure, GQuark field, ...)
{
va_list varargs;
g_return_if_fail (structure != NULL);
va_start (varargs, field);
gst_structure_id_set_valist_internal (structure, field, varargs);
va_end (varargs);
}
/**
* gst_structure_id_set_valist:
* @structure: a #GstStructure
* @fieldname: the name of the field to set
* @varargs: variable arguments
*
* va_list form of gst_structure_id_set().
*
* Since: 0.10.10
*/
void
gst_structure_id_set_valist (GstStructure * structure,
GQuark fieldname, va_list varargs)
{
g_return_if_fail (structure != NULL);
g_return_if_fail (IS_MUTABLE (structure));
gst_structure_id_set_valist_internal (structure, fieldname, varargs);
}
/** /**
* gst_structure_id_new: * gst_structure_id_new:
* @name_quark: name of new structure * @name_quark: name of new structure
@ -702,7 +725,7 @@ gst_structure_id_new (GQuark name_quark, GQuark field_quark, ...)
s = gst_structure_id_empty_new (name_quark); s = gst_structure_id_empty_new (name_quark);
va_start (varargs, field_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); va_end (varargs);
return s; return s;