gobject: rework freezing once during object initialization

During object initialization, we may want to freeze the notifications,
but only do so once (and once unfreeze at the end).

Rework how that was done. We can avoid an additional GData lookup.
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 05246be..5b1b108 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -668,7 +668,8 @@
                                  GDestroyNotify *destroy_notify,
                                  gpointer user_data)
 {
-  GObject *object = user_data;
+  GObject *object = ((gpointer *) user_data)[0];
+  gboolean freeze_always = GPOINTER_TO_INT (((gpointer *) user_data)[1]);
   GObjectNotifyQueue *nqueue = *data;
 
   if (!nqueue)
@@ -678,6 +679,13 @@
       *data = nqueue;
       *destroy_notify = g_free;
     }
+  else if (!freeze_always)
+    {
+      /* The caller only wants to ensure we are frozen once. If we are already frozen,
+       * don't freeze another time.
+       *
+       * This is only relevant during the object initialization. */
+    }
   else
     {
       if (nqueue->freeze_count == G_MAXUINT16)
@@ -695,12 +703,12 @@
 }
 
 static void
-g_object_notify_queue_freeze (GObject *object)
+g_object_notify_queue_freeze (GObject *object, gboolean freeze_always)
 {
   _g_datalist_id_update_atomic (&object->qdata,
                                 quark_notify_queue,
                                 g_object_notify_queue_freeze_cb,
-                                object);
+                                ((gpointer[]){ object, GINT_TO_POINTER (!!freeze_always) }));
 }
 
 static gpointer
@@ -1742,7 +1750,7 @@
   if (CLASS_HAS_PROPS (class) && CLASS_NEEDS_NOTIFY (class))
     {
       /* freeze object's notification queue, g_object_new_internal() preserves pairedness */
-      g_object_notify_queue_freeze (object);
+      g_object_notify_queue_freeze (object, TRUE);
     }
 
   /* mark object in-construction for notify_queue_thaw() and to allow construct-only properties */
@@ -1922,7 +1930,7 @@
     }
 #endif
 
-  g_object_notify_queue_freeze (object);
+  g_object_notify_queue_freeze (object, TRUE);
 }
 
 static inline void
@@ -2608,8 +2616,7 @@
           /* This may or may not have been setup in g_object_init().
            * If it hasn't, we do it now.
            */
-          if (!g_datalist_id_get_data (&object->qdata, quark_notify_queue))
-            g_object_notify_queue_freeze (object);
+          g_object_notify_queue_freeze (object, FALSE);
           nqueue_is_frozen = TRUE;
         }
     }
@@ -2656,8 +2663,7 @@
           /* This may or may not have been setup in g_object_init().
            * If it hasn't, we do it now.
            */
-          if (!g_datalist_id_get_data (&object->qdata, quark_notify_queue))
-            g_object_notify_queue_freeze (object);
+          g_object_notify_queue_freeze (object, FALSE);
           nqueue_is_frozen = TRUE;
         }
 
@@ -3021,7 +3027,7 @@
   /* set construction parameters */
   if (n_construct_properties)
     {
-      g_object_notify_queue_freeze (object);
+      g_object_notify_queue_freeze (object, TRUE);
       
       /* set construct properties */
       while (n_construct_properties--)
@@ -3111,7 +3117,7 @@
 
   if (_g_object_has_notify_handler (object))
     {
-      g_object_notify_queue_freeze (object);
+      g_object_notify_queue_freeze (object, TRUE);
       nqueue_is_frozen = TRUE;
     }
 
@@ -3155,7 +3161,7 @@
 
   if (_g_object_has_notify_handler (object))
     {
-      g_object_notify_queue_freeze (object);
+      g_object_notify_queue_freeze (object, TRUE);
       nqueue_is_frozen = TRUE;
     }
 
@@ -4423,7 +4429,7 @@
    * notification queue gets automatically drained when g_object_finalize() is
    * reached and the qdata is cleared.
    */
-  g_object_notify_queue_freeze (object);
+  g_object_notify_queue_freeze (object, TRUE);
   nqueue_is_frozen = TRUE;
 
   TRACE (GOBJECT_OBJECT_DISPOSE (object, G_TYPE_FROM_INSTANCE (object), 1));