summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-05-29 13:45:27 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2022-05-29 13:47:43 +0200
commitc580ee65d728b5726716516254d9c2a763f82a76 (patch)
tree4b0bbed4256366232783188ab742b435a7240e83
parent418f277ae5895083ae1d25dec6dc39cee74ff994 (diff)
downloadlibgnome-volume-control-c580ee65d728b5726716516254d9c2a763f82a76.tar.gz
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.
-rw-r--r--gvc-mixer-event-role.c19
1 files 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