[nautilus/wip/corey/fix-sort: 4/4] list-view: Only insert columns when they should be visible
- From: Corey Berla <coreyberla src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/corey/fix-sort: 4/4] list-view: Only insert columns when they should be visible
- Date: Sun, 16 Oct 2022 17:54:11 +0000 (UTC)
commit f43a7cc9bac9ccc37a784e370048c059adc7df7a
Author: Corey Berla <corey berla me>
Date: Sun Oct 16 09:43:47 2022 -0700
list-view: Only insert columns when they should be visible
In a nautilus-list-view, we create factories for the various
cells within each GtkListItem. This is designed with performance in
mind... we don't want to create hundreds of thousands of objects
in a folder where we may only look at a small number of files.
We are proactively creating every possibly LabelCell without
checking which one is visible by appending all of the columns in
setup_view_columns. This means that even though
the GtkListView may only request a couple hundred ListItems,
we end up generating thousands of LabelCells. There are currently
13 available columns of which 3 are enabled by default.
Insert the columns into the columnview only when they are
selected to be visible.
Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2498
src/nautilus-list-view.c | 39 +++++++++++++--------------------------
1 file changed, 13 insertions(+), 26 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 4ecb6c8bd..a5f7c075a 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -46,6 +46,7 @@ struct _NautilusListView
GtkColumnViewColumn *star_column;
GtkWidget *column_editor;
GHashTable *factory_to_column_map;
+ GHashTable *all_view_columns_hash;
};
G_DEFINE_TYPE (NautilusListView, nautilus_list_view, NAUTILUS_TYPE_LIST_BASE)
@@ -119,7 +120,6 @@ apply_columns_settings (NautilusListView *self,
g_autoptr (GList) view_columns = NULL;
GListModel *old_view_columns;
g_autoptr (GHashTable) visible_columns_hash = NULL;
- g_autoptr (GHashTable) old_view_columns_hash = NULL;
int column_i = 0;
file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (self));
@@ -164,25 +164,7 @@ apply_columns_settings (NautilusListView *self,
}
}
- old_view_columns_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
old_view_columns = gtk_column_view_get_columns (self->view_ui);
- for (guint i = 0; i < g_list_model_get_n_items (old_view_columns); i++)
- {
- g_autoptr (GtkColumnViewColumn) view_column = NULL;
- GtkListItemFactory *factory;
- NautilusColumn *nautilus_column;
- gchar *name;
-
- view_column = g_list_model_get_item (old_view_columns, i);
- factory = gtk_column_view_column_get_factory (view_column);
- nautilus_column = g_hash_table_lookup (self->factory_to_column_map, factory);
- g_object_get (nautilus_column, "name", &name, NULL);
- g_hash_table_insert (old_view_columns_hash, name, view_column);
- }
-
for (GList *l = all_columns; l != NULL; l = l->next)
{
g_autofree char *name = NULL;
@@ -195,7 +177,7 @@ apply_columns_settings (NautilusListView *self,
{
GtkColumnViewColumn *view_column;
- view_column = g_hash_table_lookup (old_view_columns_hash, name);
+ view_column = g_hash_table_lookup (self->all_view_columns_hash, name);
if (view_column != NULL)
{
view_columns = g_list_prepend (view_columns, view_column);
@@ -213,11 +195,7 @@ apply_columns_settings (NautilusListView *self,
view_column = g_list_model_get_item (old_view_columns, i);
if (g_list_find (view_columns, view_column) == NULL)
{
- gtk_column_view_column_set_visible (view_column, FALSE);
- }
- else
- {
- gtk_column_view_column_set_visible (view_column, TRUE);
+ gtk_column_view_remove_column (self->view_ui, view_column);
}
}
@@ -770,9 +748,11 @@ real_begin_loading (NautilusFilesView *files_view)
NautilusListView *self = NAUTILUS_LIST_VIEW (files_view);
NautilusFile *file;
+ /* We need to setup the columns before chaining up */
+ update_columns_settings_from_metadata_and_preferences (self);
+
NAUTILUS_FILES_VIEW_CLASS (nautilus_list_view_parent_class)->begin_loading (files_view);
- update_columns_settings_from_metadata_and_preferences (self);
self->sort_attribute = 0;
self->path_attribute_q = 0;
@@ -1073,6 +1053,10 @@ setup_view_columns (NautilusListView *self)
g_direct_equal,
NULL,
g_object_unref);
+ self->all_view_columns_hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ g_object_unref);
for (GList *l = nautilus_columns; l != NULL; l = l->next)
{
@@ -1134,6 +1118,8 @@ setup_view_columns (NautilusListView *self)
g_hash_table_insert (self->factory_to_column_map,
factory,
g_object_ref (nautilus_column));
+ g_hash_table_insert (self->all_view_columns_hash, g_strdup (name),
+ g_steal_pointer (&view_column));
}
}
@@ -1197,6 +1183,7 @@ nautilus_list_view_dispose (GObject *object)
g_clear_object (&self->file_path_base_location);
g_clear_pointer (&self->factory_to_column_map, g_hash_table_destroy);
+ g_clear_pointer (&self->all_view_columns_hash, g_hash_table_destroy);
G_OBJECT_CLASS (nautilus_list_view_parent_class)->dispose (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]