IconHelper: Only preload icons once
authorAlexander Larsson <alexl@redhat.com>
Thu, 30 Jan 2020 14:17:59 +0000 (15:17 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 30 Jan 2020 14:17:59 +0000 (15:17 +0100)
This limits the amount of preloading we to, which can for instance
avoid trashing if the icon cache is full, and in general do less work
when its likely to be wasted such as when e.g. background-color for an
icon helper changes.

gtk/gtkiconhelper.c

index e266887c566904e9ea31cabee697431dfbaea16c..a940b9f65701c6e2083e0d5cc414a2177852ed7c 100644 (file)
@@ -48,6 +48,7 @@ struct _GtkIconHelper
   guint use_fallback : 1;
   guint force_scale_pixbuf : 1;
   guint texture_is_symbolic : 1;
+  guint preloaded : 1;
 
   GtkWidget *owner;
   GtkCssNode *node;
@@ -184,6 +185,12 @@ _gtk_icon_helper_preload (GtkIconHelper *self)
   GIcon *gicon = NULL;
   GIcon *free_gicon = NULL;
 
+  /* Avoid constantly preloading as it may cause issues if we're trashing the icon cache */
+  if (self->preloaded)
+    return;
+
+  self->preloaded = TRUE;
+
   switch (gtk_image_definition_get_storage_type (self->def))
     {
     case GTK_IMAGE_ICON_NAME: