[libgnome-volume-control/feature/gobject-cleanups: 6/8] event-role: Improve GObject properties gunk a bit




commit c580ee65d728b5726716516254d9c2a763f82a76
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun May 29 13:45:27 2022 +0200

    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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]