[gnome-shell/wip/desktop-file-index: 18/20] app-system: Lazily create ShellApps for apps we care about



commit 1ed1a9730bf1810348394d2512216e66a35d4d00
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Sep 26 17:06:47 2013 -0400

    app-system: Lazily create ShellApps for apps we care about
    
    Rather than create all ShellApps up-front, create them lazily. We really
    had no reason to do this before as we were scanning GMenu to get all the
    apps, but doing this can remove a need for get_all, which is slow and
    memory-hungry.

 src/shell-app-system.c |   38 +++++++++++++++-----------------------
 1 files changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index cf566f1..6fab7a9 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -72,26 +72,6 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
 }
 
 static void
-load_apps (ShellAppSystem *self)
-{
-  ShellAppSystemPrivate *priv = self->priv;
-  GList *apps, *l;
-
-  apps = g_app_info_get_all ();
-  for (l = apps; l != NULL; l = l->next)
-    {
-      GAppInfo *info = l->data;
-      g_hash_table_insert (priv->id_to_app,
-                           (char *) g_app_info_get_id (info),
-                           _shell_app_new (G_DESKTOP_APP_INFO (info)));
-    }
-
-  g_list_free_full (apps, g_object_unref);
-
-  g_signal_emit (self, signals[INSTALLED_CHANGED], 0);
-}
-
-static void
 shell_app_system_init (ShellAppSystem *self)
 {
   ShellAppSystemPrivate *priv;
@@ -108,8 +88,6 @@ shell_app_system_init (ShellAppSystem *self)
   priv->startup_wm_class_to_app = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                          NULL,
                                                          (GDestroyNotify)g_object_unref);
-
-  load_apps (self);
 }
 
 static void
@@ -152,7 +130,21 @@ ShellApp *
 shell_app_system_lookup_app (ShellAppSystem   *self,
                              const char       *id)
 {
-  return g_hash_table_lookup (self->priv->id_to_app, id);
+  ShellAppSystemPrivate *priv = self->priv;
+  ShellApp *app;
+  GDesktopAppInfo *info;
+
+  app = g_hash_table_lookup (priv->id_to_app, id);
+  if (app)
+    return app;
+
+  info = g_desktop_app_info_new (id);
+  if (!info)
+    return NULL;
+
+  app = _shell_app_new (info);
+  g_hash_table_insert (priv->id_to_app, (char *) id, app);
+  return app;
 }
 
 /**


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