Blame SOURCES/window-Streamline-RestoreTabData-memory-management.patch

82f35c
From 4bdd3fad8d51e50e3539c8e04bc91538467bd236 Mon Sep 17 00:00:00 2001
82f35c
From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= <antoniof@gnome.org>
82f35c
Date: Wed, 8 Jul 2020 14:44:38 +0100
82f35c
Subject: [PATCH] window: Streamline RestoreTabData memory management
82f35c
82f35c
When restoring the back and forward lists, we make a deep copy only to
82f35c
free the data immediately afterwards.
82f35c
82f35c
Instead of reallocating the lists unnecessarily, let's just steal them.
82f35c
82f35c
Also, use g_queue_free_full() to make free_restore_tab_data() a proper
82f35c
GDestroyNotify; also define it in window-slot.c, where it belongs.
82f35c
---
82f35c
 src/nautilus-window-slot.c | 16 ++++++++++++++--
82f35c
 src/nautilus-window-slot.h |  1 +
82f35c
 src/nautilus-window.c      | 20 ++------------------
82f35c
 3 files changed, 17 insertions(+), 20 deletions(-)
82f35c
82f35c
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
82f35c
index c3260aeb0..bf040bff2 100644
82f35c
--- a/src/nautilus-window-slot.c
82f35c
+++ b/src/nautilus-window-slot.c
82f35c
@@ -155,6 +155,18 @@ static void trash_state_changed_cb (NautilusTrashMonitor *monitor,
82f35c
                                     gboolean              is_empty,
82f35c
                                     gpointer              user_data);
82f35c
 
82f35c
+void
82f35c
+free_restore_tab_data (gpointer data)
82f35c
+{
82f35c
+    RestoreTabData *tab_data = data;
82f35c
+
82f35c
+    g_list_free_full (tab_data->back_list, g_object_unref);
82f35c
+    g_list_free_full (tab_data->forward_list, g_object_unref);
82f35c
+    nautilus_file_unref (tab_data->file);
82f35c
+
82f35c
+    g_free (tab_data);
82f35c
+}
82f35c
+
82f35c
 void
82f35c
 nautilus_window_slot_restore_from_data (NautilusWindowSlot *self,
82f35c
                                         RestoreTabData     *data)
82f35c
@@ -163,9 +175,9 @@ nautilus_window_slot_restore_from_data (NautilusWindowSlot *self,
82f35c
 
82f35c
     priv = nautilus_window_slot_get_instance_private (self);
82f35c
 
82f35c
-    priv->back_list = g_list_copy_deep (data->back_list, (GCopyFunc) g_object_ref, NULL);
82f35c
+    priv->back_list = g_steal_pointer (&data->back_list);
82f35c
 
82f35c
-    priv->forward_list = g_list_copy_deep (data->forward_list, (GCopyFunc) g_object_ref, NULL);
82f35c
+    priv->forward_list = g_steal_pointer (&data->forward_list);
82f35c
 
82f35c
     priv->view_mode_before_search = data->view_before_search;
82f35c
 
82f35c
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
82f35c
index 573357d9b..bda1a920f 100644
82f35c
--- a/src/nautilus-window-slot.h
82f35c
+++ b/src/nautilus-window-slot.h
82f35c
@@ -125,4 +125,5 @@ RestoreTabData* nautilus_window_slot_get_restore_tab_data (NautilusWindowSlot *s
82f35c
 /* Only used by slot-dnd */
82f35c
 NautilusView*  nautilus_window_slot_get_current_view       (NautilusWindowSlot *slot);
82f35c
 
82f35c
+void free_restore_tab_data                                 (gpointer data);
82f35c
 #endif /* NAUTILUS_WINDOW_SLOT_H */
82f35c
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
82f35c
index 1f8d5208e..175da6fce 100644
82f35c
--- a/src/nautilus-window.c
82f35c
+++ b/src/nautilus-window.c
82f35c
@@ -79,8 +79,6 @@ static GtkWidget *nautilus_window_ensure_location_entry (NautilusWindow *window)
82f35c
 static void close_slot (NautilusWindow     *window,
82f35c
                         NautilusWindowSlot *slot,
82f35c
                         gboolean            remove_from_notebook);
82f35c
-static void free_restore_tab_data (gpointer data,
82f35c
-                                   gpointer user_data);
82f35c
 
82f35c
 /* Sanity check: highest mouse button value I could find was 14. 5 is our
82f35c
  * lower threshold (well-documented to be the one of the button events for the
82f35c
@@ -1374,7 +1372,7 @@ action_restore_tab (GSimpleAction *action,
82f35c
     nautilus_window_slot_open_location_full (slot, location, flags, NULL);
82f35c
     nautilus_window_slot_restore_from_data (slot, data);
82f35c
 
82f35c
-    free_restore_tab_data (data, NULL);
82f35c
+    free_restore_tab_data (data);
82f35c
 }
82f35c
 
82f35c
 static void
82f35c
@@ -2501,19 +2499,6 @@ nautilus_window_destroy (GtkWidget *object)
82f35c
     GTK_WIDGET_CLASS (nautilus_window_parent_class)->destroy (object);
82f35c
 }
82f35c
 
82f35c
-static void
82f35c
-free_restore_tab_data (gpointer data,
82f35c
-                       gpointer user_data)
82f35c
-{
82f35c
-    RestoreTabData *tab_data = data;
82f35c
-
82f35c
-    g_list_free_full (tab_data->back_list, g_object_unref);
82f35c
-    g_list_free_full (tab_data->forward_list, g_object_unref);
82f35c
-    nautilus_file_unref (tab_data->file);
82f35c
-
82f35c
-    g_free (tab_data);
82f35c
-}
82f35c
-
82f35c
 static void
82f35c
 nautilus_window_finalize (GObject *object)
82f35c
 {
82f35c
@@ -2548,8 +2533,7 @@ nautilus_window_finalize (GObject *object)
82f35c
                                           G_CALLBACK (nautilus_window_on_undo_changed),
82f35c
                                           window);
82f35c
 
82f35c
-    g_queue_foreach (priv->tab_data_queue, (GFunc) free_restore_tab_data, NULL);
82f35c
-    g_queue_free (priv->tab_data_queue);
82f35c
+    g_queue_free_full (priv->tab_data_queue, free_restore_tab_data);
82f35c
 
82f35c
     g_object_unref (priv->pad_controller);
82f35c
 
82f35c
-- 
82f35c
2.35.1
82f35c