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

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