gobject: Avoid the ref/unref dance if assigning the same to a value

g_value_set_object could lead to perform unneeded ref/unref operations in
case we were trying to set again an object to a GValue
This commit is contained in:
Marco Trevisan (Treviño) 2022-12-20 02:09:09 +01:00
parent cbee90b8a4
commit bc59ed8fba
2 changed files with 5 additions and 1 deletions

View File

@ -4502,8 +4502,11 @@ g_value_set_object (GValue *value,
g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
if G_UNLIKELY (value->data[0].v_pointer == v_object)
return;
old = value->data[0].v_pointer;
if (v_object)
{
g_return_if_fail (G_IS_OBJECT (v_object));

View File

@ -719,6 +719,7 @@ test_value_transform_object (void)
g_value_init (&src, types[s]);
g_value_set_object (&src, object);
g_value_set_object (&src, g_value_get_object (&src));
for (d = 0; d < G_N_ELEMENTS (types); d++)
{