[libdazzle/libdazzle-3-26] theming: avoid thrashing the GtkIconTheme



commit 9f4e1e538b498f251185962952e358ce630ea9e7
Author: Christian Hergert <chergert redhat com>
Date:   Sun Sep 24 01:11:30 2017 -0700

    theming: avoid thrashing the GtkIconTheme
    
    The icon theme is very sensitive to performance degradation by
    adding lots of places for it to look for icons. Therefore, we
    want to ensure that we only add those directories to the icon
    theme if they already exist.

 src/theming/dzl-theme-manager.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/theming/dzl-theme-manager.c b/src/theming/dzl-theme-manager.c
index f3cd6dd..96136c8 100644
--- a/src/theming/dzl-theme-manager.c
+++ b/src/theming/dzl-theme-manager.c
@@ -123,9 +123,25 @@ dzl_theme_manager_add_resources (DzlThemeManager *self,
   icons_dir = g_build_filename (real_path, "icons", NULL);
   g_debug ("Loading icon resources from %s", icons_dir);
   if (!g_str_equal (real_path, resource_path))
-    gtk_icon_theme_add_resource_path (theme, icons_dir);
+    {
+      g_auto(GStrv) children = NULL;
+
+      /* Okay, tihs is a resource-based path. Make sure the
+       * path contains children so we don't slow down the
+       * theme loading code with tons of useless directories.
+       */
+      children = g_resources_enumerate_children (icons_dir, 0, NULL);
+      if (children != NULL && children[0] != NULL)
+        gtk_icon_theme_add_resource_path (theme, icons_dir);
+    }
   else
-    gtk_icon_theme_append_search_path (theme, icons_dir);
+    {
+      /* Make sure the directory exists so that we don't needlessly
+       * slow down the icon loading paths.
+       */
+      if (g_file_test (icons_dir, G_FILE_TEST_IS_DIR))
+        gtk_icon_theme_append_search_path (theme, icons_dir);
+    }
 }
 
 /**


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