mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
gstvalue: Avoid temporary allocation
The problem is that: * g_value_init will end up allocating an internal list/array * g_value_copy *clears* the existing value by calling the free func and then the copy function (creating it again) To avoid that alloc/free/alloc cycle, directly call the appropriate function Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/453>
This commit is contained in:
parent
62f553873b
commit
ee4d2f9178
1 changed files with 15 additions and 1 deletions
|
@ -6358,10 +6358,24 @@ gst_value_register (const GstValueTable * table)
|
|||
void
|
||||
gst_value_init_and_copy (GValue * dest, const GValue * src)
|
||||
{
|
||||
GType type;
|
||||
|
||||
g_return_if_fail (G_IS_VALUE (src));
|
||||
g_return_if_fail (dest != NULL);
|
||||
|
||||
g_value_init (dest, G_VALUE_TYPE (src));
|
||||
type = G_VALUE_TYPE (src);
|
||||
/* We need to shortcut GstValueList/GstValueArray copying because:
|
||||
* * g_value_init would end up allocating something
|
||||
* * which g_value_copy would then free and re-alloc.
|
||||
*
|
||||
* Instead directly call the copy */
|
||||
if (type == GST_TYPE_LIST || type == GST_TYPE_ARRAY) {
|
||||
dest->g_type = type;
|
||||
gst_value_copy_list_or_array (src, dest);
|
||||
return;
|
||||
}
|
||||
|
||||
g_value_init (dest, type);
|
||||
g_value_copy (src, dest);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue