[glib/gobject-speedups: 10/13] Avoid property notification during g_object_set




commit 720f85be89339b0510c1d87523c71b4833303cd2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 15 07:56:43 2022 -0400

    Avoid property notification during g_object_set
    
    If we have no nontrivial notify vfunc, and no signal
    handlers for notify, we don't need to maintain the
    notify queue. No need to notify if nobody's listening.

 gobject/gobject.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 771d0c16c3..71ff73c8ef 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1347,7 +1347,8 @@ g_object_notify_by_spec_internal (GObject    *object,
 
   notify_pspec = get_notify_pspec (pspec);
 
-  if (notify_pspec != NULL)
+  if (notify_pspec != NULL &&
+      _g_object_has_notify_handler (object))
     {
       GObjectNotifyQueue *nqueue;
 
@@ -2501,7 +2502,7 @@ g_object_setv (GObject       *object,
                const GValue   values[])
 {
   guint i;
-  GObjectNotifyQueue *nqueue;
+  GObjectNotifyQueue *nqueue = NULL;
   GParamSpec *pspec;
   GType obj_type;
 
@@ -2512,7 +2513,11 @@ g_object_setv (GObject       *object,
 
   g_object_ref (object);
   obj_type = G_OBJECT_TYPE (object);
-  nqueue = g_object_notify_queue_freeze (object, FALSE);
+
+  if (n_properties > 1 &&
+      _g_object_has_notify_handler (object))
+    nqueue = g_object_notify_queue_freeze (object, FALSE);
+
   for (i = 0; i < n_properties; i++)
     {
       pspec = g_param_spec_pool_lookup (pspec_pool, names[i], obj_type, TRUE);
@@ -2523,7 +2528,9 @@ g_object_setv (GObject       *object,
       object_set_property (object, pspec, &values[i], nqueue);
     }
 
-  g_object_notify_queue_thaw (object, nqueue);
+  if (nqueue)
+    g_object_notify_queue_thaw (object, nqueue);
+
   g_object_unref (object);
 }
 
@@ -2541,13 +2548,15 @@ g_object_set_valist (GObject     *object,
                     const gchar *first_property_name,
                     va_list      var_args)
 {
-  GObjectNotifyQueue *nqueue;
+  GObjectNotifyQueue *nqueue = NULL;
   const gchar *name;
   
   g_return_if_fail (G_IS_OBJECT (object));
-  
+
   g_object_ref (object);
-  nqueue = g_object_notify_queue_freeze (object, FALSE);
+
+  if (_g_object_has_notify_handler (object))
+    nqueue = g_object_notify_queue_freeze (object, FALSE);
   
   name = first_property_name;
   while (name)
@@ -2579,8 +2588,11 @@ g_object_set_valist (GObject      *object,
       name = va_arg (var_args, gchar*);
     }
 
-  g_object_notify_queue_thaw (object, nqueue);
+  if (nqueue)
+    g_object_notify_queue_thaw (object, nqueue);
+
   g_object_unref (object);
+
 }
 
 static inline gboolean


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