2007-09-12 Federico Mena Quintero Fix the critical part of https://bugzilla.novell.com/show_bug.cgi?id=303869 http://bugzilla.gnome.org/show_bug.cgi?id=476342 * gtk/gtkiconcachevalidator.c (_gtk_icon_cache_validate): To avoid massive page-in when starting an application, don't validate icon caches unless we have "GTK_DEBUG=icontheme". * gtk/gtkiconcache.c (_gtk_icon_cache_new_for_path): Tell _gtk_icon_cache_validate() that it is not mandatory to do the validation. * gtk/updateiconcache.c (validate_file): Here it *is* mandatory to do the validation. diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c index 7cce508..be2d9fb 100644 --- a/gtk/gtkiconcache.c +++ b/gtk/gtkiconcache.c @@ -127,7 +127,7 @@ _gtk_icon_cache_new_for_path (const gchar *path) info.n_directories = 0; info.flags = CHECK_OFFSETS|CHECK_STRINGS; - if (!_gtk_icon_cache_validate (&info)) + if (!_gtk_icon_cache_validate (&info, path, FALSE)) { g_mapped_file_free (map); g_warning ("Icon cache '%s' is invalid\n", cache_filename); diff --git a/gtk/gtkiconcachevalidator.c b/gtk/gtkiconcachevalidator.c index 73cf351..757b34a 100644 --- a/gtk/gtkiconcachevalidator.c +++ b/gtk/gtkiconcachevalidator.c @@ -17,6 +17,7 @@ * Boston, MA 02111-1307, USA. */ #include "config.h" +#include "gtkdebug.h" #include "gtkiconcachevalidator.h" #include @@ -370,7 +371,10 @@ check_hash (CacheInfo *info, /** * _gtk_icon_cache_validate: - * @info: a CacheInfo structure + * @info: a CacheInfo structure + * @icon_path: Name of the file that is being checked (unused except for debug output) + * @mandatory: Whether to actually perform the validation; if FALSE, validation will only + * be performed if there is an environment variable GTK_DEBUG=icontheme. * * Validates the icon cache passed in the @cache and * @cache_size fields of the @info structure. The @@ -383,11 +387,19 @@ check_hash (CacheInfo *info, * Return value: %TRUE if the cache is valid */ gboolean -_gtk_icon_cache_validate (CacheInfo *info) +_gtk_icon_cache_validate (CacheInfo *info, + const gchar *icon_path, + gboolean mandatory) { guint32 hash_offset; guint32 directory_list_offset; + if (!mandatory && (gtk_debug_flags & GTK_DEBUG_ICONTHEME) == 0) + return TRUE; + + GTK_NOTE (ICONTHEME, + g_print ("validating icon cache for %s", icon_path)); + if (!check_version (info)) return FALSE; check ("header, hash offset", get_uint32 (info, 4, &hash_offset)); diff --git a/gtk/gtkiconcachevalidator.h b/gtk/gtkiconcachevalidator.h index 9b22e85..5ed3b26 100644 --- a/gtk/gtkiconcachevalidator.h +++ b/gtk/gtkiconcachevalidator.h @@ -37,7 +37,9 @@ typedef struct { gint flags; } CacheInfo; -gboolean _gtk_icon_cache_validate (CacheInfo *info); +gboolean _gtk_icon_cache_validate (CacheInfo *info, + const gchar *icon_path, + gboolean mandatory); G_END_DECLS diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c index fd4ca66..6ad7b1d 100644 --- a/gtk/updateiconcache.c +++ b/gtk/updateiconcache.c @@ -49,6 +49,10 @@ static gboolean validate = FALSE; static gchar *var_name = "-"; static gboolean remove_empty_cache = FALSE; +guint gtk_debug_flags; /* HACK: gtkiconcachevalidator.c needs this from + * gtkdebug.h/gtkmain.c, but we don't link to libgtk. + */ + /* Quite ugly - if we just add the c file to the * list of sources in Makefile.am, libtool complains. */ @@ -1419,7 +1423,7 @@ validate_file (const gchar *file) info.n_directories = 0; info.flags = CHECK_OFFSETS|CHECK_STRINGS|CHECK_PIXBUFS; - if (!_gtk_icon_cache_validate (&info)) + if (!_gtk_icon_cache_validate (&info, file, TRUE)) { g_mapped_file_free (map); return FALSE;