diff options
author | António Fernandes <antoniof@gnome.org> | 2018-11-29 14:24:29 +0000 |
---|---|---|
committer | Ernestas Kulik <ernestask@gnome.org> | 2018-12-12 15:15:42 +0000 |
commit | ddded19a7852a5f002ceed561ac9e0310b69b637 (patch) | |
tree | a8c9e9b8671ca01f3d661812033a4ea12bb4d6d6 /src/nautilus-search-engine-simple.c | |
parent | 3feda7826615a93613502d9679a8bc3c24c01342 (diff) | |
download | nautilus-ddded19a7852a5f002ceed561ac9e0310b69b637.tar.gz |
query: Port MIME type filter to GPtrArray
We have been using doubly-linked lists to store MIME type names strings.
But this is not a great container for strings, and we are copying the
lists multiple times.
So, use GPtrArray instead. This avoids copies thanks to reference
counting, and enables autocleanup thanks to built-in data freeing.
Diffstat (limited to 'src/nautilus-search-engine-simple.c')
-rw-r--r-- | src/nautilus-search-engine-simple.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c index 32ac41734..8def0a644 100644 --- a/src/nautilus-search-engine-simple.c +++ b/src/nautilus-search-engine-simple.c @@ -47,7 +47,7 @@ typedef struct NautilusSearchEngineSimple *engine; GCancellable *cancellable; - GList *mime_types; + GPtrArray *mime_types; GList *found_list; GQueue *directories; /* GFiles */ @@ -119,7 +119,7 @@ search_thread_data_free (SearchThreadData *data) g_hash_table_destroy (data->visited); g_object_unref (data->cancellable); g_object_unref (data->query); - g_list_free_full (data->mime_types, g_free); + g_clear_pointer (&data->mime_types, g_ptr_array_unref); g_list_free_full (data->hits, g_object_unref); g_object_unref (data->engine); @@ -216,7 +216,6 @@ visit_directory (GFile *dir, const char *mime_type, *display_name; gdouble match; gboolean is_hidden, found; - GList *l; const char *id; gboolean visited; guint64 atime; @@ -226,7 +225,7 @@ visit_directory (GFile *dir, gchar *uri; enumerator = g_file_enumerate_children (dir, - data->mime_types != NULL ? + data->mime_types->len > 0 ? STD_ATTRIBUTES "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE : @@ -262,14 +261,14 @@ visit_directory (GFile *dir, match = nautilus_query_matches_string (data->query, display_name); found = (match > -1); - if (found && data->mime_types) + if (found && data->mime_types->len > 0) { mime_type = g_file_info_get_content_type (info); found = FALSE; - for (l = data->mime_types; mime_type != NULL && l != NULL; l = l->next) + for (gint i = 0; i < data->mime_types->len; i++) { - if (g_content_type_is_a (mime_type, l->data)) + if (g_content_type_is_a (mime_type, g_ptr_array_index (data->mime_types, i))) { found = TRUE; break; |