[Xfce4-commits] <thunar:master> Use slices in icon factory for keys.

Nick Schermer noreply at xfce.org
Tue Oct 30 22:06:02 CET 2012


Updating branch refs/heads/master
         to 36c0bc57e750e0f8e6b7438884439076b8720c54 (commit)
       from b6ce9c30fb184db37cd50566d2f6c10220504747 (commit)

commit 36c0bc57e750e0f8e6b7438884439076b8720c54
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Oct 30 18:01:02 2012 +0100

    Use slices in icon factory for keys.

 thunar/thunar-icon-factory.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/thunar/thunar-icon-factory.c b/thunar/thunar-icon-factory.c
index 2079a0a..f2bf1d4 100644
--- a/thunar/thunar-icon-factory.c
+++ b/thunar/thunar-icon-factory.c
@@ -88,6 +88,7 @@ static void       thunar_icon_factory_mark_recently_used    (ThunarIconFactory
 static guint      thunar_icon_key_hash                      (gconstpointer             data);
 static gboolean   thunar_icon_key_equal                     (gconstpointer             a,
                                                              gconstpointer             b);
+static void       thunar_icon_key_free                      (gpointer                  data);
 static GdkPixbuf *thunar_icon_factory_load_fallback         (ThunarIconFactory        *factory,
                                                              gint                      size);
 
@@ -202,7 +203,7 @@ thunar_icon_factory_init (ThunarIconFactory *factory)
                                                          0, thunar_icon_factory_changed, factory, NULL);
 
   /* allocate the hash table for the icon cache */
-  factory->icon_cache = g_hash_table_new_full (thunar_icon_key_hash, thunar_icon_key_equal, g_free, g_object_unref);
+  factory->icon_cache = g_hash_table_new_full (thunar_icon_key_hash, thunar_icon_key_equal, thunar_icon_key_free, g_object_unref);
 }
 
 
@@ -534,10 +535,9 @@ thunar_icon_factory_lookup_icon (ThunarIconFactory *factory,
         }
 
       /* generate a key for the new cached icon */
-      key = g_malloc (sizeof (ThunarIconKey) + strlen (name) + 1);
-      key->name = ((gchar *) key) + sizeof (ThunarIconKey);
+      key = g_slice_new (ThunarIconKey);
       key->size = size;
-      strcpy (key->name, name);
+      key->name = g_strdup (name);
 
       /* insert the new icon into the cache */
       g_hash_table_insert (factory->icon_cache, key, pixbuf);
@@ -623,6 +623,17 @@ thunar_icon_key_equal (gconstpointer a,
 
 
 
+static void
+thunar_icon_key_free (gpointer data)
+{
+  ThunarIconKey *key = data;
+
+  g_free (key->name);
+  g_slice_free (ThunarIconKey, key);
+}
+
+
+
 static GdkPixbuf*
 thunar_icon_factory_load_fallback (ThunarIconFactory *factory,
                                    gint               size)


More information about the Xfce4-commits mailing list