[gimp/wip/nielsdg/bye-bye-stock-id: 2/3] viewable: Use g_object_notify_by_pspec()



commit 88b9359efca91ad5a54e81fed12d8bb6ea22c47a
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Tue May 12 17:50:04 2020 +0200

    viewable: Use g_object_notify_by_pspec()
    
    From commit 529aa743:
    
    > `g_object_notify()` actually takes a global lock to look up the
    > property by its name, which means there is a performance hit (albeit
    > tiny) every time this function is called. For this reason, always try
    > to use `g_object_notify_by_pspec()` instead.
    
    While just _loading_ GIMP on my machine (ie during the splash screen)
    `g_object_notify (viewable, "icon-name");` got called more than 4000
    times already, so it's not an unused path.
    
    Note that it's also less easy to make an accidental typo when using
    `g_object_notify_by_pspec()`, as the compiler will complain about the
    enum value being incorrect.

 app/core/gimpviewable.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c
index 087e4db194..17ab8ca4d0 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -46,8 +46,10 @@ enum
   PROP_0,
   PROP_ICON_NAME,
   PROP_ICON_PIXBUF,
-  PROP_FROZEN
+  PROP_FROZEN,
+  N_PROPS
 };
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
 
 enum
 {
@@ -208,23 +210,22 @@ gimp_viewable_class_init (GimpViewableClass *klass)
   klass->set_expanded            = NULL;
   klass->get_expanded            = NULL;
 
-  GIMP_CONFIG_PROP_STRING (object_class, PROP_ICON_NAME, "icon-name",
-                           NULL, NULL,
+  obj_props[PROP_ICON_NAME] =
+      g_param_spec_string ("icon-name", NULL, NULL,
                            NULL,
-                           GIMP_PARAM_STATIC_STRINGS);
+                           GIMP_CONFIG_PARAM_FLAGS);
 
-  GIMP_CONFIG_PROP_OBJECT (object_class, PROP_ICON_PIXBUF,
-                           "icon-pixbuf",
-                           NULL, NULL,
+  obj_props[PROP_ICON_PIXBUF] =
+      g_param_spec_object ("icon-pixbuf", NULL, NULL,
                            GDK_TYPE_PIXBUF,
-                           G_PARAM_CONSTRUCT |
-                           GIMP_PARAM_STATIC_STRINGS);
-
-  g_object_class_install_property (object_class, PROP_FROZEN,
-                                   g_param_spec_boolean ("frozen",
-                                                         NULL, NULL,
-                                                         FALSE,
-                                                         GIMP_PARAM_READABLE));
+                           GIMP_CONFIG_PARAM_FLAGS);
+
+  obj_props[PROP_FROZEN] =
+      g_param_spec_boolean ("frozen", NULL, NULL,
+                            FALSE,
+                            GIMP_PARAM_READABLE);
+
+  g_object_class_install_properties (object_class, N_PROPS, obj_props);
 }
 
 static void
@@ -1261,7 +1262,7 @@ gimp_viewable_set_icon_name (GimpViewable *viewable,
 
   gimp_viewable_invalidate_preview (viewable);
 
-  g_object_notify (G_OBJECT (viewable), "icon-name");
+  g_object_notify_by_pspec (G_OBJECT (viewable), obj_props[PROP_ICON_NAME]);
 }
 
 void
@@ -1280,7 +1281,7 @@ gimp_viewable_preview_freeze (GimpViewable *viewable)
       if (GIMP_VIEWABLE_GET_CLASS (viewable)->preview_freeze)
         GIMP_VIEWABLE_GET_CLASS (viewable)->preview_freeze (viewable);
 
-      g_object_notify (G_OBJECT (viewable), "frozen");
+      g_object_notify_by_pspec (G_OBJECT (viewable), obj_props[PROP_FROZEN]);
     }
 }
 
@@ -1313,7 +1314,7 @@ gimp_viewable_preview_thaw (GimpViewable *viewable)
           gimp_viewable_invalidate_preview (viewable);
         }
 
-      g_object_notify (G_OBJECT (viewable), "frozen");
+      g_object_notify_by_pspec (G_OBJECT (viewable), obj_props[PROP_FROZEN]);
 
       if (GIMP_VIEWABLE_GET_CLASS (viewable)->preview_thaw)
         GIMP_VIEWABLE_GET_CLASS (viewable)->preview_thaw (viewable);


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