[gtk/action-muxer-speedup: 2317/2323] Speed up action muxer setup more



commit 38984282c57b1474a9ce94b79d01d2723fc31682
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Apr 24 01:11:13 2020 -0400

    Speed up action muxer setup more
    
    Don't emit signals for group insertion/removal
    if nobody is listening.

 gtk/gtkactionmuxer.c | 53 +++++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index bcd7ca2934..963055fd9b 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -94,6 +94,9 @@ static GParamSpec *properties[NUM_PROPERTIES];
 
 guint accel_signal;
 
+static guint action_added_signal;
+static guint action_removed_signal;
+
 typedef struct
 {
   GtkActionMuxer *muxer;
@@ -359,13 +362,8 @@ static void
 emit_action_added (GtkActionMuxer *muxer,
                    GtkActionMuxer *parent)
 {
-  static guint signal_id = 0;
-
-  if (signal_id == 0)
-    signal_id = g_signal_lookup ("action-added", G_OBJECT_TYPE (muxer));
-
-  if (g_signal_has_handler_pending (muxer, signal_id, 0, FALSE))
-    { 
+  if (g_signal_has_handler_pending (muxer, action_added_signal, 0, FALSE))
+    {
       gchar **actions;
       gchar **it;
 
@@ -387,13 +385,10 @@ notify_observers_removed (GtkActionMuxer *muxer,
   Action *action;
 
   g_hash_table_iter_init (&iter, muxer->observed_actions);
-  while (g_hash_table_iter_next (&iter, (gpointer *)&action_name, (gpointer *)&action)) 
+  while (g_hash_table_iter_next (&iter, (gpointer *)&action_name, (gpointer *)&action))
     {
       GSList *node;
 
-      if (!action->watchers)
-        continue;
-
       for (node = action->watchers; node; node = node->next)
         gtk_action_observer_action_removed (node->data,
                                             GTK_ACTION_OBSERVABLE (muxer),
@@ -405,13 +400,8 @@ static void
 emit_action_removed (GtkActionMuxer *muxer,
                      GtkActionMuxer *parent)
 {
-  static guint signal_id = 0;
-
-  if (signal_id == 0)
-    signal_id = g_signal_lookup ("action-removed", G_OBJECT_TYPE (muxer));
-
-  if (g_signal_has_handler_pending (muxer, signal_id, 0, FALSE))
-    { 
+  if (g_signal_has_handler_pending (muxer, action_removed_signal, 0, FALSE))
+    {
       gchar **actions;
       gchar **it;
 
@@ -461,12 +451,14 @@ gtk_action_muxer_action_added_to_group (GActionGroup *action_group,
                                         gpointer      user_data)
 {
   Group *group = user_data;
-  gchar *fullname;
 
-  fullname = g_strconcat (group->prefix, ".", action_name, NULL);
-  gtk_action_muxer_action_added (group->muxer, fullname, action_group, action_name);
-
-  g_free (fullname);
+  if (g_hash_table_size (group->muxer->observed_actions) > 0 ||
+      g_signal_has_handler_pending (group->muxer, action_added_signal, 0, FALSE))
+    {
+      char *fullname = g_strconcat (group->prefix, ".", action_name, NULL);
+      gtk_action_muxer_action_added (group->muxer, fullname, action_group, action_name);
+      g_free (fullname);
+    }
 }
 
 static void
@@ -498,12 +490,14 @@ gtk_action_muxer_action_removed_from_group (GActionGroup *action_group,
                                             gpointer      user_data)
 {
   Group *group = user_data;
-  gchar *fullname;
 
-  fullname = g_strconcat (group->prefix, ".", action_name, NULL);
-  gtk_action_muxer_action_removed (group->muxer, fullname);
-
-  g_free (fullname);
+  if (g_hash_table_size (group->muxer->observed_actions) > 0 ||
+      g_signal_has_handler_pending (group->muxer, action_removed_signal, 0, FALSE))
+    {
+      char *fullname = g_strconcat (group->prefix, ".", action_name, NULL);
+      gtk_action_muxer_action_removed (group->muxer, fullname);
+      g_free (fullname);
+    }
 }
 
 static void
@@ -1045,6 +1039,9 @@ gtk_action_muxer_class_init (GObjectClass *class)
   class->finalize = gtk_action_muxer_finalize;
   class->dispose = gtk_action_muxer_dispose;
 
+  action_added_signal = g_signal_lookup ("action-added", GTK_TYPE_ACTION_MUXER);
+  action_removed_signal = g_signal_lookup ("action-removed", GTK_TYPE_ACTION_MUXER);
+
   accel_signal = g_signal_new (I_("primary-accel-changed"),
                                GTK_TYPE_ACTION_MUXER,
                                G_SIGNAL_RUN_LAST,


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