[gtk+] icontheme: Drop unnecessary allocation



commit 39e848c0eb396de601af26ca0aa4d29492e5f533
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Oct 17 11:34:36 2016 +0100

    icontheme: Drop unnecessary allocation
    
    Use a static array for the known icon sizes, now that we don't allow
    registering custom icon sizes any more. This allows us to cut a one-off
    allocation that makes Valgrind sad.

 gtk/gtkicontheme.c |  137 +++++++++++++++++++---------------------------------
 1 files changed, 49 insertions(+), 88 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index b208b63..a2255d4 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -5556,107 +5556,68 @@ typedef struct _IconSize IconSize;
 
 struct _IconSize
 {
-  gint size;
-  gchar *name;
-
-  gint width;
-  gint height;
-};
+  int size;
 
-typedef struct _IconAlias IconAlias;
+  const char *name;
 
-struct _IconAlias
-{
-  gchar *name;
-  gint   target;
+  int width;
+  int height;
 };
 
-static GHashTable *icon_aliases = NULL;
-static IconSize *icon_sizes = NULL;
-static gint      icon_sizes_allocated = 0;
-static gint      icon_sizes_used = 0;
-
-static void
-init_icon_sizes (void)
-{
-  if (icon_sizes == NULL)
-    {
-#define NUM_BUILTIN_SIZES 7
-      /*gint i;*/
-
-      icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
-
-      icon_sizes = g_new (IconSize, NUM_BUILTIN_SIZES);
-      icon_sizes_allocated = NUM_BUILTIN_SIZES;
-      icon_sizes_used = NUM_BUILTIN_SIZES;
-
-      icon_sizes[GTK_ICON_SIZE_INVALID].size = 0;
-      icon_sizes[GTK_ICON_SIZE_INVALID].name = NULL;
-      icon_sizes[GTK_ICON_SIZE_INVALID].width = 0;
-      icon_sizes[GTK_ICON_SIZE_INVALID].height = 0;
-
-      /* the name strings aren't copied since we don't ever remove
-       * icon sizes, so we don't need to know whether they're static.
-       * Even if we did I suppose removing the builtin sizes would be
-       * disallowed.
-       */
-
-      icon_sizes[GTK_ICON_SIZE_MENU].size = GTK_ICON_SIZE_MENU;
-      icon_sizes[GTK_ICON_SIZE_MENU].name = "gtk-menu";
-      icon_sizes[GTK_ICON_SIZE_MENU].width = 16;
-      icon_sizes[GTK_ICON_SIZE_MENU].height = 16;
-
-      icon_sizes[GTK_ICON_SIZE_BUTTON].size = GTK_ICON_SIZE_BUTTON;
-      icon_sizes[GTK_ICON_SIZE_BUTTON].name = "gtk-button";
-      icon_sizes[GTK_ICON_SIZE_BUTTON].width = 16;
-      icon_sizes[GTK_ICON_SIZE_BUTTON].height = 16;
-
-      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].size = GTK_ICON_SIZE_SMALL_TOOLBAR;
-      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].name = "gtk-small-toolbar";
-      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].width = 16;
-      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].height = 16;
-
-      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].size = GTK_ICON_SIZE_LARGE_TOOLBAR;
-      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].name = "gtk-large-toolbar";
-      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].width = 24;
-      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].height = 24;
-
-      icon_sizes[GTK_ICON_SIZE_DND].size = GTK_ICON_SIZE_DND;
-      icon_sizes[GTK_ICON_SIZE_DND].name = "gtk-dnd";
-      icon_sizes[GTK_ICON_SIZE_DND].width = 32;
-      icon_sizes[GTK_ICON_SIZE_DND].height = 32;
-
-      icon_sizes[GTK_ICON_SIZE_DIALOG].size = GTK_ICON_SIZE_DIALOG;
-      icon_sizes[GTK_ICON_SIZE_DIALOG].name = "gtk-dialog";
-      icon_sizes[GTK_ICON_SIZE_DIALOG].width = 48;
-      icon_sizes[GTK_ICON_SIZE_DIALOG].height = 48;
-
-      g_assert ((GTK_ICON_SIZE_DIALOG + 1) == NUM_BUILTIN_SIZES);
-
-      /* Alias everything to itself. */
-      /*i = 1; [> skip invalid size <]*/
-      /*while (i < NUM_BUILTIN_SIZES)*/
-        /*{*/
-          /*gtk_icon_size_register_alias (icon_sizes[i].name, icon_sizes[i].size);*/
-
-          /*++i;*/
-        /*}*/
-
-#undef NUM_BUILTIN_SIZES
-    }
-}
+static const IconSize icon_sizes[] = {
+  [GTK_ICON_SIZE_INVALID] = {
+    .size = 0,
+    .name = NULL,
+    .width = 0,
+    .height = 0,
+  },
+  [GTK_ICON_SIZE_MENU] = {
+    .size = GTK_ICON_SIZE_MENU,
+    .name = "gtk-menu",
+    .width = 16,
+    .height = 16,
+  },
+  [GTK_ICON_SIZE_BUTTON] = {
+    .size = GTK_ICON_SIZE_BUTTON,
+    .name = "gtk-button",
+    .width = 16,
+    .height = 16,
+  },
+  [GTK_ICON_SIZE_SMALL_TOOLBAR] = {
+    .size = GTK_ICON_SIZE_SMALL_TOOLBAR,
+    .name = "gtk-small-toolbar",
+    .width = 16,
+    .height = 16,
+  },
+  [GTK_ICON_SIZE_LARGE_TOOLBAR] = {
+    .size = GTK_ICON_SIZE_LARGE_TOOLBAR,
+    .name = "gtk-large-toolbar",
+    .width = 24,
+    .height = 24,
+  },
+  [GTK_ICON_SIZE_DND] = {
+    .size = GTK_ICON_SIZE_DND,
+    .name = "gtk-dnd",
+    .width = 32,
+    .height = 32,
+  },
+  [GTK_ICON_SIZE_DIALOG] = {
+    .size = GTK_ICON_SIZE_DIALOG,
+    .name = "gtk-dialog",
+    .width = 48,
+    .height = 48,
+  },
+};
 
 static gboolean
 icon_size_lookup_intern (GtkIconSize  size,
                          gint        *widthp,
                          gint        *heightp)
 {
-  init_icon_sizes ();
-
   if (size == (GtkIconSize)-1)
     return FALSE;
 
-  if (size >= icon_sizes_used)
+  if (size >= G_N_ELEMENTS (icon_sizes))
     return FALSE;
 
   if (size == GTK_ICON_SIZE_INVALID)


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