From 7823e8120d75e366246279c888865b7d6ffeb679 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 6 Feb 2024 11:24:27 -0800 Subject: [PATCH] filechooserwidget: Load recent files in bulk We add recent files one at a time which is incredibly wasteful. This is most obvious when the action is SAVE or OPEN_FOLDER because we aren't limiting the number of recent files (as we are with OPEN), so for me it took about 5 seconds to open a file dialog with OPEN_FOLDER since the default location is recents. --- gtk/gtkfilechooserwidget.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index b2bce9f138..fd27b55631 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -5924,6 +5924,7 @@ recent_start_loading (GtkFileChooserWidget *impl) { const int limit = DEFAULT_RECENT_FILES_LIMIT; const char *app_name = g_get_application_name (); + GList *files = NULL; GList *l; int n; @@ -5941,31 +5942,30 @@ recent_start_loading (GtkFileChooserWidget *impl) !gtk_recent_info_has_application (info, app_name)) continue; - file = g_file_new_for_uri (gtk_recent_info_get_uri (info)); - _gtk_file_system_model_add_and_query_file (impl->recent_model, - file, - MODEL_ATTRIBUTES); - g_object_unref (file); + files = g_list_prepend (files, file); n++; if (limit != -1 && n >= limit) break; } + files = g_list_reverse (files); + _gtk_file_system_model_add_and_query_files (impl->recent_model, + files, + MODEL_ATTRIBUTES); + g_list_free_full (files, g_object_unref); + g_set_object (&impl->model_for_search, impl->recent_model); } else { GList *folders; - GList *l; folders = _gtk_file_chooser_extract_recent_folders (items); - - for (l = folders; l; l = l->next) - _gtk_file_system_model_add_and_query_file (impl->recent_model, - G_FILE (l->data), - MODEL_ATTRIBUTES); + _gtk_file_system_model_add_and_query_files (impl->recent_model, + folders, + MODEL_ATTRIBUTES); g_list_free_full (folders, g_object_unref); }