event-role: Improve GObject properties gunk a bit

Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
This commit is contained in:
Niels De Graef 2022-05-29 13:45:27 +02:00 committed by Bastien Nocera
parent c73d7cf20c
commit f6d6fe577f

View File

@ -42,8 +42,10 @@ struct GvcMixerEventRolePrivate
enum enum
{ {
PROP_0, PROP_0,
PROP_DEVICE PROP_DEVICE,
N_PROPS
}; };
static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_event_role_finalize (GObject *object); static void gvc_mixer_event_role_finalize (GObject *object);
@ -115,7 +117,7 @@ gvc_mixer_event_role_set_device (GvcMixerEventRole *role,
g_free (role->priv->device); g_free (role->priv->device);
role->priv->device = g_strdup (device); role->priv->device = g_strdup (device);
g_object_notify (G_OBJECT (role), "device"); g_object_notify_by_pspec (G_OBJECT (role), obj_props[PROP_DEVICE]);
return TRUE; return TRUE;
} }
@ -169,13 +171,12 @@ gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass)
stream_class->push_volume = gvc_mixer_event_role_push_volume; stream_class->push_volume = gvc_mixer_event_role_push_volume;
stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted; stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted;
g_object_class_install_property (object_class, obj_props[PROP_DEVICE] = g_param_spec_string ("device",
PROP_DEVICE,
g_param_spec_string ("device",
"Device", "Device",
"Device", "Device",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
} }
static void static void