[glib/gobject-speedups: 23/26] Avoid g_object_ref/unref in some cases




commit 283cdd23a6284e2107e9c9ef8c2e4aff84891c95
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue May 17 07:11:19 2022 -0400

    Avoid g_object_ref/unref in some cases
    
    We only need to take a ref on the object when
    we call out to external code (ie around
    ->dispatch_properties_changed). If we avoid
    the signal emission, we can avoid the ref/unref
    too.

 gobject/gobject.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index aeced5e8cd..e3096b6f83 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1369,9 +1369,15 @@ g_object_notify_by_spec_internal (GObject    *object,
           g_object_notify_queue_thaw (object, nqueue);
         }
       else
-        /* not frozen, so just dispatch the notification directly */
-        G_OBJECT_GET_CLASS (object)
-          ->dispatch_properties_changed (object, 1, &notify_pspec);
+        {
+          g_object_ref (object);
+
+          /* not frozen, so just dispatch the notification directly */
+          G_OBJECT_GET_CLASS (object)
+            ->dispatch_properties_changed (object, 1, &notify_pspec);
+
+          g_object_unref (object);
+        }
     }
 }
 
@@ -1402,7 +1408,6 @@ g_object_notify (GObject     *object,
   if (g_atomic_int_get (&object->ref_count) == 0)
     return;
   
-  g_object_ref (object);
   /* We don't need to get the redirect target
    * (by, e.g. calling g_object_class_find_property())
    * because g_object_notify_queue_add() does that
@@ -1419,7 +1424,6 @@ g_object_notify (GObject     *object,
               property_name);
   else
     g_object_notify_by_spec_internal (object, pspec);
-  g_object_unref (object);
 }
 
 /**
@@ -1478,9 +1482,7 @@ g_object_notify_by_pspec (GObject    *object,
   if (g_atomic_int_get (&object->ref_count) == 0)
     return;
 
-  g_object_ref (object);
   g_object_notify_by_spec_internal (object, pspec);
-  g_object_unref (object);
 }
 
 /**


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