[glib/gobject-performance] Only add object to list new objects when it has a custom constructor



commit c8e4e425954d1a5612bf58730255eba34950c067
Author: Benjamin Otte <otte gnome org>
Date:   Thu Oct 8 20:01:15 2009 +0200

    Only add object to list new objects when it has a custom constructor
    
    This works around the need to take a custom mutex twice and add the
    object to a GSList of objects that are currently in construction for the
    common case. Only when the constructor is overwritten do we use the
    previous behavior and allow things like singleton objects.
    
    The only slightly incompatible change is that previously, it was ok to
    call g_object_set() on construct-only properties while the object was
    initialized. This will now fail. If that behavior is needed, setting a
    custom constructor that just chains up will reenable this functionality.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=557151

 gobject/gobject.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 102652d..72b4d04 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -116,6 +116,8 @@
 #define CLASS_HAS_PROPS_FLAG 0x1
 #define CLASS_HAS_PROPS(class) \
     ((class)->flags & CLASS_HAS_PROPS_FLAG)
+#define CLASS_HAS_CUSTOM_CONSTRUCTOR(class) \
+    ((class)->constructor != g_object_constructor)
 
 /* --- signals --- */
 enum {
@@ -701,10 +703,13 @@ g_object_init (GObject		*object,
       g_object_notify_queue_freeze (object, &property_notify_context);
     }
 
-  /* enter construction list for notify_queue_thaw() and to allow construct-only properties */
-  G_LOCK (construction_mutex);
-  construction_objects = g_slist_prepend (construction_objects, object);
-  G_UNLOCK (construction_mutex);
+  if (CLASS_HAS_CUSTOM_CONSTRUCTOR (class))
+    {
+      /* enter construction list for notify_queue_thaw() and to allow construct-only properties */
+      G_LOCK (construction_mutex);
+      construction_objects = g_slist_prepend (construction_objects, object);
+      G_UNLOCK (construction_mutex);
+    }
 
 #ifdef	G_ENABLE_DEBUG
   IF_DEBUG (OBJECTS)
@@ -1243,10 +1248,15 @@ g_object_newv (GType       object_type,
   g_free (cvalues);
 
  did_construction:
-  /* adjust freeze_count according to g_object_init() and remaining properties */
-  G_LOCK (construction_mutex);
-  newly_constructed = slist_maybe_remove (&construction_objects, object);
-  G_UNLOCK (construction_mutex);
+  if (CLASS_HAS_CUSTOM_CONSTRUCTOR (class))
+    {
+      /* adjust freeze_count according to g_object_init() and remaining properties */
+      G_LOCK (construction_mutex);
+      newly_constructed = slist_maybe_remove (&construction_objects, object);
+      G_UNLOCK (construction_mutex);
+    }
+  else
+    newly_constructed = TRUE;
 
   if (CLASS_HAS_PROPS (class))
     {



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