From: Matthias Clasen Date: Thu, 12 Jan 2023 05:35:43 +0000 (-0500) Subject: iconcache: Be a bit less wasteful X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~8^2~71^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d226dc3812207d80fc62d715cdbdf3cc3926b395;p=gtk4.git iconcache: Be a bit less wasteful --- diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c index 706de5450d..d6ecd4f2b0 100644 --- a/gtk/gtkiconcache.c +++ b/gtk/gtkiconcache.c @@ -188,6 +188,7 @@ gtk_icon_cache_list_icons_in_directory (GtkIconCache *cache, guint32 image_list_offset, n_images; int i, j; GHashTable *icons = NULL; + GString *string; directory_index = get_directory_index (cache, directory); @@ -197,6 +198,8 @@ gtk_icon_cache_list_icons_in_directory (GtkIconCache *cache, hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); + string = g_string_new (""); + for (i = 0; i < n_buckets; i++) { chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i); @@ -223,15 +226,18 @@ gtk_icon_cache_list_icons_in_directory (GtkIconCache *cache, const char *name = cache->buffer + name_offset; const char *interned_name; guint32 hash_flags = 0; + int len; /* Icons named foo.symbolic.png are stored in the cache as "foo.symbolic" with ICON_CACHE_FLAG_PNG, * but we convert it internally to ICON_CACHE_FLAG_SYMBOLIC_PNG. * Otherwise we use the same enum values and names as on disk. */ - if (g_str_has_suffix (name, ".symbolic") && (flags & ICON_CACHE_FLAG_PNG_SUFFIX) != 0) + + len = strlen (name); + if (g_str_equal (name + len - strlen (".symbolic"), ".symbolic") && (flags & ICON_CACHE_FLAG_PNG_SUFFIX) != 0) { - char *converted_name = g_strndup (name, strlen (name) - 9); - interned_name = gtk_string_set_add (set, converted_name); - g_free (converted_name); + g_string_set_size (string, 0); + g_string_append_len (string, name, len - strlen (".symbolic")); + interned_name = gtk_string_set_add (set, string->str); flags |= ICON_CACHE_FLAG_SYMBOLIC_PNG_SUFFIX; flags &= ~ICON_CACHE_FLAG_PNG_SUFFIX; } @@ -249,5 +255,7 @@ gtk_icon_cache_list_icons_in_directory (GtkIconCache *cache, } } + g_string_free (string, TRUE); + return icons; }