[glib/wip/notify-performance: 4/8] [notify] lift some logic out of _notify_queue_add



commit 1e59fb3b0679b503355f0b0a77ffee5577c9dcef
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Nov 16 12:31:20 2011 +0000

    [notify] lift some logic out of _notify_queue_add
    
    Lift the check-if-READABLE and redirect-target logic from out of
    g_object_notify_queue_add() into its own function, get_notify_pspec().
    
    Use that function at the site of our two calls to
    g_object_notify_queue_add().

 gobject/gobject.c            |   38 ++++++++++++++++++++++++++++++++++----
 gobject/gobjectnotifyqueue.c |   25 ++++++++-----------------
 2 files changed, 42 insertions(+), 21 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 6e20aa0..3d61634 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -972,15 +972,39 @@ g_object_freeze_notify (GObject *object)
   g_object_unref (object);
 }
 
+static GParamSpec *
+get_notify_pspec (GParamSpec *pspec)
+{
+  GParamSpec *redirected;
+
+  /* we don't notify on non-READABLE parameters */
+  if (~pspec->flags & G_PARAM_READABLE)
+    return NULL;
+
+  /* if the paramspec is redirected, notify on the target */
+  redirected = g_param_spec_get_redirect_target (pspec);
+  if (redirected != NULL)
+    return redirected;
+
+  /* else, notify normally */
+  return pspec;
+}
+
 static inline void
 g_object_notify_by_spec_internal (GObject    *object,
 				  GParamSpec *pspec)
 {
   GObjectNotifyQueue *nqueue;
+  GParamSpec *notify_pspec;
 
-  nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
-  g_object_notify_queue_add (object, nqueue, pspec);
-  g_object_notify_queue_thaw (object, nqueue);
+  notify_pspec = get_notify_pspec (pspec);
+
+  if (notify_pspec != NULL)
+    {
+      nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
+      g_object_notify_queue_add (object, nqueue, notify_pspec);
+      g_object_notify_queue_thaw (object, nqueue);
+    }
 }
 
 /**
@@ -1196,8 +1220,14 @@ object_set_property (GObject             *object,
     }
   else
     {
+      GParamSpec *notify_pspec;
+
       class->set_property (object, param_id, &tmp_value, pspec);
-      g_object_notify_queue_add (object, nqueue, pspec);
+
+      notify_pspec = get_notify_pspec (pspec);
+
+      if (notify_pspec != NULL)
+        g_object_notify_queue_add (object, nqueue, notify_pspec);
     }
   g_value_unset (&tmp_value);
 }
diff --git a/gobject/gobjectnotifyqueue.c b/gobject/gobjectnotifyqueue.c
index 45250ed..41831c6 100644
--- a/gobject/gobjectnotifyqueue.c
+++ b/gobject/gobjectnotifyqueue.c
@@ -137,26 +137,17 @@ g_object_notify_queue_add (GObject            *object,
 			   GObjectNotifyQueue *nqueue,
 			   GParamSpec	      *pspec)
 {
-  if (pspec->flags & G_PARAM_READABLE)
-    {
-      GParamSpec *redirect;
-
-      redirect = g_param_spec_get_redirect_target (pspec);
-      if (redirect)
-        pspec = redirect;
-
-      G_LOCK(notify_lock);
-
-      g_return_if_fail (nqueue->n_pspecs < 65535);
+  G_LOCK(notify_lock);
 
-      if (g_slist_find (nqueue->pspecs, pspec) == NULL)
-        {
-          nqueue->pspecs = g_slist_prepend (nqueue->pspecs, pspec);
-          nqueue->n_pspecs++;
-        }
+  g_return_if_fail (nqueue->n_pspecs < 65535);
 
-      G_UNLOCK(notify_lock);
+  if (g_slist_find (nqueue->pspecs, pspec) == NULL)
+    {
+      nqueue->pspecs = g_slist_prepend (nqueue->pspecs, pspec);
+      nqueue->n_pspecs++;
     }
+
+  G_UNLOCK(notify_lock);
 }
 
 G_END_DECLS



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