[glib/wip/menus: 40/61] Drop the 'pending' logic in the exporter



commit 8c3e67d32126ff602902c7a37f66ccf8c8819cf2
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Oct 22 15:16:34 2011 -0400

    Drop the 'pending' logic in the exporter
    
    This was to avoid unbounded recursion, but that's sort of silly if you
    really think about it.  Are we going to be attacked by our own menus?
    
    It's faster and easier without this.

 gio/gmenuexporter.c |   34 ++++++++++++++++------------------
 1 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/gio/gmenuexporter.c b/gio/gmenuexporter.c
index 7912ae3..c57ec75 100644
--- a/gio/gmenuexporter.c
+++ b/gio/gmenuexporter.c
@@ -298,8 +298,8 @@ struct _GMenuExporterGroup
   guint          id;
 
   GHashTable *menus;
-  GSList     *pending;
   guint       next_menu_id;
+  gboolean    prepared;
 
   gint subscribed;
 };
@@ -312,35 +312,31 @@ g_menu_exporter_group_check_if_useless (GMenuExporterGroup *group)
       g_menu_exporter_remove_group (group->exporter, group->id);
 
       g_hash_table_unref (group->menus);
-      g_slist_free (group->pending);
 
       g_slice_free (GMenuExporterGroup, group);
     }
 }
 
 static void
-g_menu_exporter_group_clear_pending (GMenuExporterGroup *group)
+g_menu_exporter_group_subscribe (GMenuExporterGroup *group,
+                                 GVariantBuilder    *builder)
 {
-  while (group->pending)
+  GHashTableIter iter;
+  gpointer key, val;
+
+  if (!group->prepared)
     {
       GMenuExporterMenu *menu;
 
-      menu = g_hash_table_lookup (group->menus, group->pending->data);
-      group->pending = g_slist_delete_link (group->pending, group->pending);
-      g_assert (menu != NULL);
+      /* set this first, so that any menus created during the
+       * preparation of the first menu also end up in the prepared
+       * state.
+       * */
+      group->prepared = TRUE;
 
+      menu = g_hash_table_lookup (group->menus, 0);
       g_menu_exporter_menu_prepare (menu);
     }
-}
-
-static void
-g_menu_exporter_group_subscribe (GMenuExporterGroup *group,
-                                 GVariantBuilder    *builder)
-{
-  GHashTableIter iter;
-  gpointer key, val;
-
-  g_menu_exporter_group_clear_pending (group);
 
   group->subscribed++;
 
@@ -409,7 +405,9 @@ g_menu_exporter_group_add_menu (GMenuExporterGroup *group,
   id = group->next_menu_id++;
   menu = g_menu_exporter_menu_new (group, id, model);
   g_hash_table_insert (group->menus, GINT_TO_POINTER (id), menu);
-  group->pending = g_slist_prepend (group->pending, GINT_TO_POINTER (id));
+
+  if (group->prepared)
+    g_menu_exporter_menu_prepare (menu);
 
   return menu;
 }



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