Commit eee85d39 authored by Matthias Clasen's avatar Matthias Clasen

Avoid more GFile<>uri roundtrips

Make GtkSearchHit carry a GFile instead of an uri. Most of the
search engines already have the object around, and converting
to an uri and back is unnecessary extra work.
parent f7bba525
...@@ -7007,9 +7007,7 @@ search_engine_hits_added_cb (GtkSearchEngine *engine, ...@@ -7007,9 +7007,7 @@ search_engine_hits_added_cb (GtkSearchEngine *engine,
for (l = hits; l; l = l->next) for (l = hits; l; l = l->next)
{ {
GtkSearchHit *hit = (GtkSearchHit *)l->data; GtkSearchHit *hit = (GtkSearchHit *)l->data;
file = g_file_new_for_uri (hit->uri); file = g_object_ref (hit->file);
if (!file)
continue;
if (hit->info) if (hit->info)
{ {
files_with_info = g_list_prepend (files_with_info, file); files_with_info = g_list_prepend (files_with_info, file);
......
...@@ -311,7 +311,7 @@ search_hit_equal (gconstpointer a, gconstpointer b) ...@@ -311,7 +311,7 @@ search_hit_equal (gconstpointer a, gconstpointer b)
const GtkSearchHit *ha = (const GtkSearchHit *)a; const GtkSearchHit *ha = (const GtkSearchHit *)a;
const GtkSearchHit *hb = (const GtkSearchHit *)b; const GtkSearchHit *hb = (const GtkSearchHit *)b;
return g_str_equal (ha->uri, hb->uri); return g_file_equal (ha->file, hb->file);
} }
...@@ -320,7 +320,7 @@ search_hit_hash (gconstpointer a) ...@@ -320,7 +320,7 @@ search_hit_hash (gconstpointer a)
{ {
const GtkSearchHit *ha = (const GtkSearchHit *)a; const GtkSearchHit *ha = (const GtkSearchHit *)a;
return g_str_hash (ha->uri); return g_file_hash (ha->file);
} }
GtkSearchHit * GtkSearchHit *
...@@ -329,7 +329,7 @@ _gtk_search_hit_dup (GtkSearchHit *hit) ...@@ -329,7 +329,7 @@ _gtk_search_hit_dup (GtkSearchHit *hit)
GtkSearchHit *dup; GtkSearchHit *dup;
dup = g_new (GtkSearchHit, 1); dup = g_new (GtkSearchHit, 1);
dup->uri = g_strdup (hit->uri); dup->file = g_object_ref (hit->file);
if (hit->info) if (hit->info)
dup->info = g_object_ref (hit->info); dup->info = g_object_ref (hit->info);
else else
...@@ -341,7 +341,7 @@ _gtk_search_hit_dup (GtkSearchHit *hit) ...@@ -341,7 +341,7 @@ _gtk_search_hit_dup (GtkSearchHit *hit)
void void
_gtk_search_hit_free (GtkSearchHit *hit) _gtk_search_hit_free (GtkSearchHit *hit)
{ {
g_free (hit->uri); g_clear_object (&hit->file);
g_clear_object (&hit->info); g_clear_object (&hit->info);
g_free (hit); g_free (hit);
} }
......
...@@ -42,7 +42,7 @@ typedef struct _GtkSearchHit GtkSearchHit; ...@@ -42,7 +42,7 @@ typedef struct _GtkSearchHit GtkSearchHit;
struct _GtkSearchHit struct _GtkSearchHit
{ {
gchar *uri; GFile *file;
GFileInfo *info; /* may be NULL */ GFileInfo *info; /* may be NULL */
}; };
......
...@@ -99,7 +99,7 @@ do_search (gpointer data) ...@@ -99,7 +99,7 @@ do_search (gpointer data)
file = _gtk_file_system_model_get_file (model->model, &iter); file = _gtk_file_system_model_get_file (model->model, &iter);
hit = g_new (GtkSearchHit, 1); hit = g_new (GtkSearchHit, 1);
hit->uri = g_file_get_uri (file); hit->file = g_object_ref (file);
hit->info = g_object_ref (info); hit->info = g_object_ref (info);
hits = g_list_prepend (hits, hit); hits = g_list_prepend (hits, hit);
} }
......
...@@ -248,7 +248,7 @@ visit_directory (GFile *dir, SearchThreadData *data) ...@@ -248,7 +248,7 @@ visit_directory (GFile *dir, SearchThreadData *data)
GtkSearchHit *hit; GtkSearchHit *hit;
hit = g_new (GtkSearchHit, 1); hit = g_new (GtkSearchHit, 1);
hit->uri = g_file_get_uri (child); hit->file = g_object_ref (child);
hit->info = g_object_ref (info); hit->info = g_object_ref (info);
data->hits = g_list_prepend (data->hits, hit); data->hits = g_list_prepend (data->hits, hit);
} }
......
...@@ -300,7 +300,7 @@ query_callback (GObject *object, ...@@ -300,7 +300,7 @@ query_callback (GObject *object,
v = g_variant_iter_next_value (&iter); v = g_variant_iter_next_value (&iter);
strv = g_variant_get_strv (v, NULL); strv = g_variant_get_strv (v, NULL);
hit[i].uri = (gchar*)strv[0]; hit[i].file = g_file_new_for_uri (strv[0]);
hit[i].info = NULL; hit[i].info = NULL;
g_free (strv); g_free (strv);
hits = g_list_prepend (hits, &hit[i]); hits = g_list_prepend (hits, &hit[i]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment