mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-28 20:05:38 +00:00
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:
parent
7e5a9580ef
commit
608628d10d
1 changed files with 85 additions and 62 deletions
|
@ -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,46 +541,13 @@ gst_structure_take_value (GstStructure * structure, const gchar * fieldname,
|
|||
g_quark_from_string (fieldname), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_structure_set:
|
||||
* @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,
|
||||
static void
|
||||
gst_structure_set_valist_internal (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));
|
||||
|
||||
while (fieldname) {
|
||||
GstStructureField field = { 0 };
|
||||
|
||||
|
@ -601,51 +576,53 @@ gst_structure_set_valist (GstStructure * structure,
|
|||
}
|
||||
|
||||
/**
|
||||
* gst_structure_id_set:
|
||||
* gst_structure_set:
|
||||
* @structure: a #GstStructure
|
||||
* @fieldname: the GQuark for the name of the field to set
|
||||
* @fieldname: 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
|
||||
* 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_id_set (GstStructure * structure, GQuark field, ...)
|
||||
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_id_set_valist (structure, field, varargs);
|
||||
gst_structure_set_valist_internal (structure, field, varargs);
|
||||
va_end (varargs);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_structure_id_set_valist:
|
||||
* gst_structure_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
|
||||
* va_list form of gst_structure_set().
|
||||
*/
|
||||
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)
|
||||
{
|
||||
gchar *err = NULL;
|
||||
GType type;
|
||||
|
||||
g_return_if_fail (structure != NULL);
|
||||
g_return_if_fail (IS_MUTABLE (structure));
|
||||
|
||||
while (fieldname) {
|
||||
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:
|
||||
* @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);
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue