From f6d6fe577fe8060a75a889b09e73e32392fe4243 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Sun, 29 May 2022 13:45:27 +0200 Subject: [PATCH] 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. --- gvc-mixer-event-role.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gvc-mixer-event-role.c b/gvc-mixer-event-role.c index 9f5e26a..272edb0 100644 --- a/gvc-mixer-event-role.c +++ b/gvc-mixer-event-role.c @@ -42,8 +42,10 @@ struct GvcMixerEventRolePrivate enum { PROP_0, - PROP_DEVICE + PROP_DEVICE, + N_PROPS }; +static GParamSpec *obj_props[N_PROPS] = { NULL, }; 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); 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; } @@ -169,13 +171,12 @@ gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass) stream_class->push_volume = gvc_mixer_event_role_push_volume; stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted; - g_object_class_install_property (object_class, - PROP_DEVICE, - g_param_spec_string ("device", - "Device", - "Device", - NULL, - G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); + obj_props[PROP_DEVICE] = g_param_spec_string ("device", + "Device", + "Device", + NULL, + G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_PROPS, obj_props); } static void