gstvalue: Add _append_and_take_value() public variants

API: gst_value_array_append_and_take_value
API: gst_value_list_append_and_take_value

We were already using this internally, this makes it public for code
which frequently appends values which are expensive to copy (like
structures, arrays, caps, ...).

Avoids copies of the values for users. The passed GValue will also
be 0-memset'ed for re-use.

New users can replace this kind of code:
gst_value_*_append_value(mycontainer, &myvalue);
g_value_unset(&myvalue);

by:

gst_value_*_append_and_take_value(mycontainer, &myvalue);

https://bugzilla.gnome.org/show_bug.cgi?id=701632
This commit is contained in:
Edward Hervey 2013-06-05 11:02:50 +02:00
parent e1f520f27c
commit 2e1db58e11
4 changed files with 58 additions and 13 deletions

View file

@ -825,8 +825,7 @@ gst_buffer_pool_config_add_option (GstStructure * config, const gchar * option)
} }
g_value_init (&option_value, G_TYPE_STRING); g_value_init (&option_value, G_TYPE_STRING);
g_value_set_string (&option_value, option); g_value_set_string (&option_value, option);
gst_value_array_append_value ((GValue *) value, &option_value); gst_value_array_append_and_take_value ((GValue *) value, &option_value);
g_value_unset (&option_value);
} }
/** /**

View file

@ -145,9 +145,9 @@ static gchar *gst_string_take_and_wrap (gchar * s);
static gchar *gst_string_unwrap (const gchar * s); static gchar *gst_string_unwrap (const gchar * s);
static void gst_value_move (GValue * dest, GValue * src); static void gst_value_move (GValue * dest, GValue * src);
static void gst_value_list_append_and_take_value (GValue * value, static void _gst_value_list_append_and_take_value (GValue * value,
GValue * append_value); GValue * append_value);
static void gst_value_array_append_and_take_value (GValue * value, static void _gst_value_array_append_and_take_value (GValue * value,
GValue * append_value); GValue * append_value);
static inline GstValueTable * static inline GstValueTable *
@ -413,17 +413,37 @@ gst_value_list_or_array_are_compatible (const GValue * value1,
return FALSE; return FALSE;
} }
static void static inline void
gst_value_list_append_and_take_value (GValue * value, GValue * append_value) _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
{ {
g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1); g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
memset (append_value, 0, sizeof (GValue)); memset (append_value, 0, sizeof (GValue));
} }
/**
* gst_value_list_append_and_take_value:
* @value: a #GValue of type #GST_TYPE_LIST
* @append_value: (transfer full): the value to append
*
* Appends @append_value to the GstValueList in @value.
*
* Since: 1.2
*/
void
gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
{
g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
g_return_if_fail (G_IS_VALUE (append_value));
g_return_if_fail (gst_value_list_or_array_are_compatible (value,
append_value));
_gst_value_list_append_and_take_value (value, append_value);
}
/** /**
* gst_value_list_append_value: * gst_value_list_append_value:
* @value: a #GValue of type #GST_TYPE_LIST * @value: a #GValue of type #GST_TYPE_LIST
* @append_value: the value to append * @append_value: (transfer none): the value to append
* *
* Appends @append_value to the GstValueList in @value. * Appends @append_value to the GstValueList in @value.
*/ */
@ -672,13 +692,33 @@ gst_value_array_append_value (GValue * value, const GValue * append_value)
g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1); g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
} }
static void static inline void
gst_value_array_append_and_take_value (GValue * value, GValue * append_value) _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
{ {
g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1); g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
memset (append_value, 0, sizeof (GValue)); memset (append_value, 0, sizeof (GValue));
} }
/**
* gst_value_array_append_and_take_value:
* @value: a #GValue of type #GST_TYPE_ARRAY
* @append_value: (transfer full): the value to append
*
* Appends @append_value to the GstValueArray in @value.
*
* Since: 1.2
*/
void
gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
{
g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
g_return_if_fail (G_IS_VALUE (append_value));
g_return_if_fail (gst_value_list_or_array_are_compatible (value,
append_value));
_gst_value_array_append_and_take_value (value, append_value);
}
/** /**
* gst_value_array_prepend_value: * gst_value_array_prepend_value:
* @value: a #GValue of type #GST_TYPE_ARRAY * @value: a #GValue of type #GST_TYPE_ARRAY
@ -3594,7 +3634,7 @@ gst_value_intersect_list (GValue * dest, const GValue * value1,
gst_value_move (dest, &intersection); gst_value_move (dest, &intersection);
ret = TRUE; ret = TRUE;
} else if (GST_VALUE_HOLDS_LIST (dest)) { } else if (GST_VALUE_HOLDS_LIST (dest)) {
gst_value_list_append_and_take_value (dest, &intersection); _gst_value_list_append_and_take_value (dest, &intersection);
} else { } else {
GValue temp; GValue temp;
@ -3641,7 +3681,7 @@ gst_value_intersect_array (GValue * dest, const GValue * src1,
g_value_unset (dest); g_value_unset (dest);
return FALSE; return FALSE;
} }
gst_value_array_append_and_take_value (dest, &val); _gst_value_array_append_and_take_value (dest, &val);
} }
return TRUE; return TRUE;
@ -4118,7 +4158,7 @@ gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
ret = TRUE; ret = TRUE;
} else if (G_VALUE_HOLDS (dest, ltype) } else if (G_VALUE_HOLDS (dest, ltype)
&& !G_VALUE_HOLDS (&subtraction, ltype)) { && !G_VALUE_HOLDS (&subtraction, ltype)) {
gst_value_list_append_and_take_value (dest, &subtraction); _gst_value_list_append_and_take_value (dest, &subtraction);
} else { } else {
GValue temp; GValue temp;
@ -5089,7 +5129,7 @@ gst_value_fixate (GValue * dest, const GValue * src)
gst_value_init_and_copy (&kid, orig_kid); gst_value_init_and_copy (&kid, orig_kid);
else else
res = TRUE; res = TRUE;
gst_value_array_append_and_take_value (dest, &kid); _gst_value_array_append_and_take_value (dest, &kid);
} }
if (!res) if (!res)

View file

@ -418,6 +418,8 @@ gboolean gst_value_deserialize (GValue *dest,
/* list */ /* list */
void gst_value_list_append_value (GValue *value, void gst_value_list_append_value (GValue *value,
const GValue *append_value); const GValue *append_value);
void gst_value_list_append_and_take_value (GValue *value,
GValue *append_value);
void gst_value_list_prepend_value (GValue *value, void gst_value_list_prepend_value (GValue *value,
const GValue *prepend_value); const GValue *prepend_value);
void gst_value_list_concat (GValue *dest, void gst_value_list_concat (GValue *dest,
@ -433,6 +435,8 @@ const GValue * gst_value_list_get_value (const GValue *value,
/* array */ /* array */
void gst_value_array_append_value (GValue *value, void gst_value_array_append_value (GValue *value,
const GValue *append_value); const GValue *append_value);
void gst_value_array_append_and_take_value (GValue *value,
GValue *append_value);
void gst_value_array_prepend_value (GValue *value, void gst_value_array_prepend_value (GValue *value,
const GValue *prepend_value); const GValue *prepend_value);
guint gst_value_array_get_size (const GValue *value); guint gst_value_array_get_size (const GValue *value);

View file

@ -1296,6 +1296,7 @@ EXPORTS
gst_util_uint64_scale_int_ceil gst_util_uint64_scale_int_ceil
gst_util_uint64_scale_int_round gst_util_uint64_scale_int_round
gst_util_uint64_scale_round gst_util_uint64_scale_round
gst_value_array_append_and_take_value
gst_value_array_append_value gst_value_array_append_value
gst_value_array_get_size gst_value_array_get_size
gst_value_array_get_type gst_value_array_get_type
@ -1330,6 +1331,7 @@ EXPORTS
gst_value_intersect gst_value_intersect
gst_value_is_fixed gst_value_is_fixed
gst_value_is_subset gst_value_is_subset
gst_value_list_append_and_take_value
gst_value_list_append_value gst_value_list_append_value
gst_value_list_concat gst_value_list_concat
gst_value_list_get_size gst_value_list_get_size