diff options
author | António Fernandes <antoniof@gnome.org> | 2021-07-26 12:55:05 +0100 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-03-27 13:14:47 +0100 |
commit | 5d788fe8217aee323f62b72f8bddec6f2b238e3f (patch) | |
tree | 9472e7266d7b7f63142a55cd911ce74faab80e1d /src/nautilus-list-view.c | |
parent | 3d5226023897caa20441f431f71f36f4e5845397 (diff) | |
download | nautilus-5d788fe8217aee323f62b72f8bddec6f2b238e3f.tar.gz |
file: Get metadata list as array
Metadata lists are attributes of type G_FILE_ATTRIBUTE_TYPE_STRINGV.
In other words, they are gchar** (arrays of strings).
Our NautilusFile API exports them as GList instead, but most calls
happen in NautilusListView, which consumes arrays of strings. So,
the conversion from array to list and back to array is wasteful.
Let's start with the getter, making it return a string array isntead.
For emblem keywords, we actually need a GList (for sorting), so make
the conversion there after the getter call.
The setter part is due in the next commit.
Diffstat (limited to 'src/nautilus-list-view.c')
-rw-r--r-- | src/nautilus-list-view.c | 51 |
1 files changed, 9 insertions, 42 deletions
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c index 749cbb7ca..eadba3135 100644 --- a/src/nautilus-list-view.c +++ b/src/nautilus-list-view.c @@ -2345,34 +2345,13 @@ get_default_visible_columns (NautilusListView *list_view) NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS); } -static GList * -get_default_visible_columns_as_list (NautilusListView *list_view) -{ - GList *res = NULL; - gint i = 0; - gchar **array; - - array = get_default_visible_columns (list_view); - - while (array[i] != NULL) - { - res = g_list_prepend (res, array[i]); - i++; - } - - g_free (array); - - return res; -} - static char ** get_visible_columns (NautilusListView *list_view) { NautilusFile *file; - g_autoptr (GList) visible_columns = NULL; + g_autofree gchar **visible_columns = NULL; g_autoptr (GFile) location = NULL; GPtrArray *res; - GList *l; g_autofree gchar *uri = NULL; gboolean can_star_current_directory; gboolean is_starred; @@ -2389,16 +2368,16 @@ get_visible_columns (NautilusListView *list_view) NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS); if (visible_columns == NULL) { - visible_columns = get_default_visible_columns_as_list (list_view); + visible_columns = get_default_visible_columns (list_view); } res = g_ptr_array_new (); - for (l = visible_columns; l != NULL; l = l->next) + for (gint i = 0; visible_columns[i] != NULL; i++) { - if (g_strcmp0 (l->data, "starred") != 0 || - (g_strcmp0 (l->data, "starred") == 0 && (can_star_current_directory || is_starred))) + if (g_strcmp0 (visible_columns[i], "starred") != 0 || + (g_strcmp0 (visible_columns[i], "starred") == 0 && (can_star_current_directory || is_starred))) { - g_ptr_array_add (res, l->data); + g_ptr_array_add (res, visible_columns[i]); } } @@ -2439,7 +2418,7 @@ static char ** get_column_order (NautilusListView *list_view) { NautilusFile *file; - GList *column_order; + gchar **column_order; file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view)); @@ -2447,21 +2426,9 @@ get_column_order (NautilusListView *list_view) (file, NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER); - if (column_order) + if (column_order != NULL) { - GPtrArray *res; - GList *l; - - res = g_ptr_array_new (); - for (l = column_order; l != NULL; l = l->next) - { - g_ptr_array_add (res, l->data); - } - g_ptr_array_add (res, NULL); - - g_list_free (column_order); - - return (char **) g_ptr_array_free (res, FALSE); + return column_order; } return get_default_column_order (list_view); |