Deduplicate PanCacheData destroying
authorArkadiy Illarionov <qarkai@gmail.com>
Sat, 13 Apr 2024 22:32:33 +0000 (01:32 +0300)
committerColin Clark <colin.clark@cclark.uk>
Sun, 14 Apr 2024 09:37:44 +0000 (10:37 +0100)
src/pan-view/pan-item.cc
src/pan-view/pan-item.h
src/pan-view/pan-view.cc

index e81fad7..0b8d591 100644 (file)
@@ -640,9 +640,7 @@ static void pan_item_image_find_size(PanWindow *pw, PanItem *pi, gint w, gint h)
                        pi->height = MAX(1, pc->cd->height * pw->image_size / 100);
 
                        pw->cache_list = g_list_remove(pw->cache_list, pc);
-                       cache_sim_data_free(pc->cd);
-                       file_data_unref(pc->fd);
-                       g_free(pc);
+                       pan_cache_data_free(pc);
                        return;
                        }
                }
@@ -989,4 +987,20 @@ void pan_text_alignment_calc(PanTextAlignment *ta, PanItem *box)
                y += height;
                }
 }
+
+
+/*
+ *-----------------------------------------------------------------------------
+ * cache data
+ *-----------------------------------------------------------------------------
+ */
+
+void pan_cache_data_free(PanCacheData *pc)
+{
+       if (!pc) return;
+
+       cache_sim_data_free(pc->cd);
+       file_data_unref(pc->fd);
+       g_free(pc);
+}
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index a992e21..ec43470 100644 (file)
@@ -98,4 +98,7 @@ void pan_text_alignment_free(PanTextAlignment *ta);
 PanItem *pan_text_alignment_add(PanTextAlignment *ta, const gchar *label, const gchar *text);
 void pan_text_alignment_calc(PanTextAlignment *ta, PanItem *box);
 
+// Cache data
+void pan_cache_data_free(PanCacheData *pc);
+
 #endif
index 82118ad..1bcc7f3 100644 (file)
@@ -618,13 +618,7 @@ GList *pan_cache_sort(GList *list, SortType method, gboolean ascend, gboolean ca
 
 static void pan_cache_free(PanWindow *pw)
 {
-       g_list_free_full(pw->cache_list, [](gpointer data)
-               {
-               auto pc = static_cast<PanCacheData *>(data);
-               cache_sim_data_free(pc->cd);
-               file_data_unref(pc->fd);
-               g_free(pc);
-               });
+       g_list_free_full(pw->cache_list, reinterpret_cast<GDestroyNotify>(pan_cache_data_free));
        pw->cache_list = nullptr;
 
        filelist_free(pw->cache_todo);