[nautilus/wip/corey/fix-sort: 2/2] list-view: Wait to append column until it should be visible




commit 9ff252c9f794fa18d814d6c25eacedd97026ea3c
Author: Corey Berla <corey berla me>
Date:   Sun Oct 16 09:43:47 2022 -0700

    list-view: Wait to append column until it 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 | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 5793e1fcd..5656d6089 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);
         }
     }
 
@@ -1073,6 +1051,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)
     {
@@ -1132,8 +1114,8 @@ setup_view_columns (NautilusListView *self)
         g_hash_table_insert (self->factory_to_column_map,
                              factory,
                              g_object_ref (nautilus_column));
-
-        gtk_column_view_append_column (self->view_ui, view_column);
+        g_hash_table_insert (self->all_view_columns_hash, g_strdup (name),
+                             g_steal_pointer (&view_column));
     }
 }
 
@@ -1197,6 +1179,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]