[gtk/class-action-init] Speed up class action hookup



commit c4a47e218f67eccb21a7aafec0189311cbc8a876
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Apr 28 20:22:26 2020 -0400

    Speed up class action hookup
    
    No need to construct a detailed signal name for
    every action when we can just look up the signal ID
    once and use the quark that the GParamSpec already
    has. Also, we don't need to loop over the actions
    every time we get a notification.

 gtk/gtkactionmuxer.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index 256406fa81..f84173fe05 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -533,24 +533,15 @@ prop_action_notify (GObject    *object,
                     GParamSpec *pspec,
                     gpointer    user_data)
 {
-  GtkActionMuxer *muxer = user_data;
-  GtkWidgetClass *klass = GTK_WIDGET_GET_CLASS (muxer->widget);
-  GtkWidgetClassPrivate *priv = klass->priv;
-  GtkWidgetAction *action = NULL;
+  GtkWidget *widget = GTK_WIDGET (object);
+  GtkWidgetAction *action = user_data;
+  GtkActionMuxer *muxer = _gtk_widget_get_action_muxer (widget, TRUE);
   GVariant *state;
 
-  g_assert ((GObject *)muxer->widget == object);
-
-  for (action = priv->actions; action; action = action->next)
-    {
-      if (action->pspec == pspec)
-        break;
-    }
-
-  g_assert (action != NULL);
+  g_assert (muxer->widget == widget);
   g_assert (action->pspec == pspec);
 
-  state = prop_action_get_state (muxer->widget, action);
+  state = prop_action_get_state (widget, action);
   gtk_action_muxer_action_state_changed (muxer, action->name, state);
   g_variant_unref (state);
 }
@@ -561,6 +552,7 @@ prop_actions_connect (GtkActionMuxer *muxer)
   GtkWidgetClassPrivate *priv;
   GtkWidgetAction *action;
   GtkWidgetClass *klass;
+  guint signal_id;
 
   if (!muxer->widget)
     return;
@@ -570,17 +562,20 @@ prop_actions_connect (GtkActionMuxer *muxer)
   if (!priv->actions)
     return;
 
+  signal_id = g_signal_lookup ("notify", G_TYPE_OBJECT);
+
   for (action = priv->actions; action; action = action->next)
     {
-      char *detailed;
-
       if (!action->pspec)
         continue;
 
-      detailed = g_strconcat ("notify::", action->pspec->name, NULL);
-      g_signal_connect (muxer->widget, detailed,
-                        G_CALLBACK (prop_action_notify), muxer);
-      g_free (detailed);
+      g_signal_connect_closure_by_id (muxer->widget,
+                                      signal_id,
+                                      g_param_spec_get_name_quark (action->pspec),
+                                      g_cclosure_new (G_CALLBACK (prop_action_notify),
+                                                                  action,
+                                                                  NULL),
+                                      FALSE);
     }
 }
 


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