summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2020-07-08 14:44:38 +0100
committerAntónio Fernandes <antoniojpfernandes@gmail.com>2020-07-12 16:27:10 +0000
commit5561219e34d0925ea752ffd87c13cd95258e3172 (patch)
tree38e8e0a64a4b06d8d9565680e12db4979d14524c /src
parentfb3cf79cbd277effbeb36669a52cf517c5544dcb (diff)
downloadnautilus-5561219e34d0925ea752ffd87c13cd95258e3172.tar.gz
window: Streamline RestoreTabData memory management
When restoring the back and forward lists, we make a deep copy only to free the data immediately afterwards. Instead of reallocating the lists unnecessarily, let's just steal them. Also, use g_queue_free_full() to make free_restore_tab_data() a proper GDestroyNotify; also define it in window-slot.c, where it belongs.
Diffstat (limited to 'src')
-rw-r--r--src/nautilus-window-slot.c16
-rw-r--r--src/nautilus-window-slot.h2
-rw-r--r--src/nautilus-window.c20
3 files changed, 18 insertions, 20 deletions
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 3bf011519..342ff35e2 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -178,6 +178,18 @@ static GMenuModel *real_get_templates_menu (NautilusWindowSlot *self);
static void nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *self);
void
+free_restore_tab_data (gpointer data)
+{
+ RestoreTabData *tab_data = data;
+
+ g_list_free_full (tab_data->back_list, g_object_unref);
+ g_list_free_full (tab_data->forward_list, g_object_unref);
+ nautilus_file_unref (tab_data->file);
+
+ g_free (tab_data);
+}
+
+void
nautilus_window_slot_restore_from_data (NautilusWindowSlot *self,
RestoreTabData *data)
{
@@ -185,9 +197,9 @@ nautilus_window_slot_restore_from_data (NautilusWindowSlot *self,
priv = nautilus_window_slot_get_instance_private (self);
- priv->back_list = g_list_copy_deep (data->back_list, (GCopyFunc) g_object_ref, NULL);
+ priv->back_list = g_steal_pointer (&data->back_list);
- priv->forward_list = g_list_copy_deep (data->forward_list, (GCopyFunc) g_object_ref, NULL);
+ priv->forward_list = g_steal_pointer (&data->forward_list);
priv->view_mode_before_search = data->view_before_search;
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index daa2f335a..42bf092ff 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -132,3 +132,5 @@ NautilusQueryEditor *nautilus_window_slot_get_query_editor (NautilusWindowSlot *
/* Only used by slot-dnd */
NautilusView* nautilus_window_slot_get_current_view (NautilusWindowSlot *slot);
+
+void free_restore_tab_data (gpointer data);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 1723d8a81..c7f076fee 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -84,8 +84,6 @@ static GtkWidget *nautilus_window_ensure_location_entry (NautilusWindow *window)
static void close_slot (NautilusWindow *window,
NautilusWindowSlot *slot,
gboolean remove_from_notebook);
-static void free_restore_tab_data (gpointer data,
- gpointer user_data);
/* Sanity check: highest mouse button value I could find was 14. 5 is our
* lower threshold (well-documented to be the one of the button events for the
@@ -1236,7 +1234,7 @@ action_restore_tab (GSimpleAction *action,
nautilus_window_slot_open_location_full (slot, location, flags, NULL);
nautilus_window_slot_restore_from_data (slot, data);
- free_restore_tab_data (data, NULL);
+ free_restore_tab_data (data);
}
static guint
@@ -2335,19 +2333,6 @@ nautilus_window_dispose (GObject *object)
}
static void
-free_restore_tab_data (gpointer data,
- gpointer user_data)
-{
- RestoreTabData *tab_data = data;
-
- g_list_free_full (tab_data->back_list, g_object_unref);
- g_list_free_full (tab_data->forward_list, g_object_unref);
- nautilus_file_unref (tab_data->file);
-
- g_free (tab_data);
-}
-
-static void
nautilus_window_finalize (GObject *object)
{
NautilusWindow *window;
@@ -2379,8 +2364,7 @@ nautilus_window_finalize (GObject *object)
G_CALLBACK (nautilus_window_on_undo_changed),
window);
- g_queue_foreach (window->tab_data_queue, (GFunc) free_restore_tab_data, NULL);
- g_queue_free (window->tab_data_queue);
+ g_queue_free_full (window->tab_data_queue, free_restore_tab_data);
g_object_unref (window->pad_controller);