summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-01-12 00:35:43 -0500
committerMatthias Clasen <mclasen@redhat.com>2023-01-12 00:36:18 -0500
commitd226dc3812207d80fc62d715cdbdf3cc3926b395 (patch)
treed2102562c8a0eec006cb65f833a0c87bc4abd91d
parent46e0fde60674da6963e0236ce13844cf2fb64802 (diff)
downloadgtk+-d226dc3812207d80fc62d715cdbdf3cc3926b395.tar.gz
iconcache: Be a bit less wasteful
-rw-r--r--gtk/gtkiconcache.c16
1 files changed, 12 insertions, 4 deletions
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;
}