Allow passing empty GValue to g_param_value_set_default()

Since we have the type of the GValue we're going to initialize, we can
allow passing an empty (but valid) GValue when retrieving the default
value of a GParamSpec.

This will eliminate additional checks and an unnecessary reset.
This commit is contained in:
Emmanuele Bassi
2019-10-26 14:01:16 +01:00
parent 1bebba0430
commit 47d558baa7

View File

@@ -595,7 +595,8 @@ g_param_spec_get_redirect_target (GParamSpec *pspec)
/** /**
* g_param_value_set_default: * g_param_value_set_default:
* @pspec: a valid #GParamSpec * @pspec: a valid #GParamSpec
* @value: a #GValue of correct type for @pspec * @value: a #GValue of correct type for @pspec; since 2.64, you
* can also pass an empty #GValue, initialized with %G_VALUE_INIT
* *
* Sets @value to its default value as specified in @pspec. * Sets @value to its default value as specified in @pspec.
*/ */
@@ -604,10 +605,18 @@ g_param_value_set_default (GParamSpec *pspec,
GValue *value) GValue *value)
{ {
g_return_if_fail (G_IS_PARAM_SPEC (pspec)); g_return_if_fail (G_IS_PARAM_SPEC (pspec));
g_return_if_fail (G_IS_VALUE (value));
g_return_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value));
g_value_reset (value); if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
{
g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec));
}
else
{
g_return_if_fail (G_IS_VALUE (value));
g_return_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value));
g_value_reset (value);
}
G_PARAM_SPEC_GET_CLASS (pspec)->value_set_default (pspec, value); G_PARAM_SPEC_GET_CLASS (pspec)->value_set_default (pspec, value);
} }