From da63cf980552f138cad22911dc42262674242818 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 18 Apr 2006 13:58:30 +0000 Subject: [PATCH] Apply a patch by Paolo Borelli to factor out a strip_suffix() function and 2006-04-18 Matthias Clasen * gtk/gtkiconcache.c: Apply a patch by Paolo Borelli to factor out a strip_suffix() function and save some memory. (#338307) --- ChangeLog | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ gtk/gtkicontheme.c | 43 ++++++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 40d875b95..9af8d196e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-04-18 Matthias Clasen + + * gtk/gtkiconcache.c: Apply a patch by Paolo Borelli to factor + out a strip_suffix() function and save some memory. (#338307) + 2006-04-18 Carlos Garnacho * gtk/gtknotebook.c (gtk_notebook_pages_allocate): removed wrong diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 40d875b95..9af8d196e 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2006-04-18 Matthias Clasen + + * gtk/gtkiconcache.c: Apply a patch by Paolo Borelli to factor + out a strip_suffix() function and save some memory. (#338307) + 2006-04-18 Carlos Garnacho * gtk/gtknotebook.c (gtk_notebook_pages_allocate): removed wrong diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 5cad50443..0fad20684 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -1026,15 +1026,27 @@ free_unthemed_icon (UnthemedIcon *unthemed_icon) g_slice_free (UnthemedIcon, unthemed_icon); } +static char * +strip_suffix (const char *filename) +{ + const char *dot; + + dot = strrchr (filename, '.'); + + if (dot == NULL) + return g_strdup (filename); + + return g_strndup (filename, dot - filename); +} + static void load_themes (GtkIconTheme *icon_theme) { GtkIconThemePrivate *priv; GDir *gdir; int base; - char *dir, *base_name, *dot; + char *dir; const char *file; - char *abs_file; UnthemedIcon *unthemed_icon; IconSuffix old_suffix, new_suffix; GTimeVal tv; @@ -1085,14 +1097,12 @@ load_themes (GtkIconTheme *icon_theme) if (new_suffix != ICON_SUFFIX_NONE) { + char *abs_file; + char *base_name; + abs_file = g_build_filename (dir, file, NULL); - - base_name = g_strdup (file); - - dot = strrchr (base_name, '.'); - if (dot) - *dot = 0; - + base_name = strip_suffix (file); + if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons, base_name))) { @@ -2161,9 +2171,6 @@ scan_directory (GtkIconThemePrivate *icon_theme, { GDir *gdir; const char *name; - char *base_name, *dot; - char *path; - IconSuffix suffix, hash_suffix; GTK_NOTE (ICONTHEME, g_print ("scanning directory %s\n", full_dir)); @@ -2177,6 +2184,10 @@ scan_directory (GtkIconThemePrivate *icon_theme, while ((name = g_dir_read_name (gdir))) { + char *path; + char *base_name; + IconSuffix suffix, hash_suffix; + if (g_str_has_suffix (name, ".icon")) { if (dir->icon_data == NULL) @@ -2195,11 +2206,9 @@ scan_directory (GtkIconThemePrivate *icon_theme, suffix = suffix_from_name (name); if (suffix == ICON_SUFFIX_NONE) continue; - - base_name = g_strdup (name); - dot = strrchr (base_name, '.'); - *dot = 0; - + + base_name = strip_suffix (name); + hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name)); g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix| suffix)); g_hash_table_insert (icon_theme->all_icons, base_name, NULL);