[gtk/action-muxer-speedup: 11/12] actionmuxer: Create groups on deman



commit 07a02958cad2d4ed74bc1d4e04c40c83ec706a3c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 19 09:56:23 2020 -0400

    actionmuxer: Create groups on deman
    
    Many action muxers don't have any groups inserted,
    so we can avoid the overhead of carrying around
    these empty hash tables.

 gtk/gtkactionmuxer.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index 38a0914ae8..9637260882 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -162,9 +162,12 @@ gtk_action_muxer_list_actions (GtkActionMuxer *muxer)
             g_hash_table_add (actions, g_strdup (action->name));
         }
 
-      g_hash_table_iter_init (&iter, muxer->groups);
-      while (g_hash_table_iter_next (&iter, (gpointer *)&prefix, (gpointer *)&group))
-        gtk_action_muxer_append_group_actions (prefix, group, actions);
+      if (muxer->groups)
+        {
+          g_hash_table_iter_init (&iter, muxer->groups);
+          while (g_hash_table_iter_next (&iter, (gpointer *)&prefix, (gpointer *)&group))
+            gtk_action_muxer_append_group_actions (prefix, group, actions);
+        }
     }
 
   keys = (char **)g_hash_table_get_keys_as_array (actions, NULL);
@@ -185,6 +188,9 @@ gtk_action_muxer_find_group (GtkActionMuxer  *muxer,
   const char *name;
   Group *group;
 
+  if (!muxer->groups)
+    return NULL;
+
   dot = strchr (full_name, '.');
 
   if (!dot)
@@ -935,7 +941,8 @@ gtk_action_muxer_finalize (GObject *object)
       g_assert_cmpint (g_hash_table_size (muxer->observed_actions), ==, 0);
       g_hash_table_unref (muxer->observed_actions);
     }
-  g_hash_table_unref (muxer->groups);
+  if (muxer->groups)
+    g_hash_table_unref (muxer->groups);
   if (muxer->primary_accels)
     g_hash_table_unref (muxer->primary_accels);
 
@@ -1013,7 +1020,6 @@ gtk_action_muxer_set_property (GObject      *object,
 static void
 gtk_action_muxer_init (GtkActionMuxer *muxer)
 {
-  muxer->groups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gtk_action_muxer_free_group);
   muxer->widget_actions_disabled = _gtk_bitmask_new ();
 }
 
@@ -1143,6 +1149,9 @@ gtk_action_muxer_insert (GtkActionMuxer *muxer,
   /* TODO: diff instead of ripout and replace */
   gtk_action_muxer_remove (muxer, prefix);
 
+  if (!muxer->groups)
+    muxer->groups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gtk_action_muxer_free_group);
+
   group = g_slice_new (Group);
   group->muxer = muxer;
   group->group = g_object_ref (action_group);
@@ -1181,6 +1190,9 @@ gtk_action_muxer_remove (GtkActionMuxer *muxer,
 {
   Group *group;
 
+  if (!muxer->groups)
+    return;
+
   group = g_hash_table_lookup (muxer->groups, prefix);
 
   if (group != NULL)


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