[gnome-software: 3/21] gs-plugin: Track properties in a static array




commit 164ae0603e94c540d73aaebd5f015c9fa96e391c
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Mar 30 12:35:19 2022 +0100

    gs-plugin: Track properties in a static array
    
    This allows for all the properties in the class to be registered in a
    single call to `g_object_class_install_properties()`, which is faster.
    
    This will make more of a difference when this class has more than one
    property.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-plugin.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 7d8167180..859a1de5f 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -79,6 +79,8 @@ typedef enum {
        PROP_FLAGS = 1,
 } GsPluginProperty;
 
+static GParamSpec *obj_props[PROP_FLAGS + 1] = { NULL, };
+
 enum {
        SIGNAL_UPDATES_CHANGED,
        SIGNAL_STATUS_CHANGED,
@@ -1717,17 +1719,25 @@ gs_plugin_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
 static void
 gs_plugin_class_init (GsPluginClass *klass)
 {
-       GParamSpec *pspec;
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
        object_class->set_property = gs_plugin_set_property;
        object_class->get_property = gs_plugin_get_property;
        object_class->finalize = gs_plugin_finalize;
 
-       pspec = g_param_spec_flags ("flags", NULL, NULL,
+       /**
+        * GsPlugin:flags:
+        *
+        * Flags which indicate various boolean properties of the plugin.
+        *
+        * These may change during the plugin’s lifetime.
+        */
+       obj_props[PROP_FLAGS] =
+               g_param_spec_flags ("flags", NULL, NULL,
                                    GS_TYPE_PLUGIN_FLAGS, GS_PLUGIN_FLAGS_NONE,
                                    G_PARAM_READWRITE);
-       g_object_class_install_property (object_class, PROP_FLAGS, pspec);
+
+       g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
 
        signals [SIGNAL_UPDATES_CHANGED] =
                g_signal_new ("updates-changed",


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