~allanlesage/indicator-appmenu/TDD-fixes

« back to all changes in this revision

Viewing changes to src/hudquery.c

  • Committer: Charles Kerr
  • Date: 2012-04-03 20:31:54 UTC
  • mfrom: (192.1.21 indicator-appmenu)
  • Revision ID: charles.kerr@canonical.com-20120403203154-2qacfj0nmpm56pnr
merge lp:~desrt/indicator-appmenu/hud-performance to improve hud-service performance and search result quality by substantially reworking the core distance algorithm and the needle/haystack assignment algorithm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
  HudSource *source;
53
53
  gchar *search_string;
 
54
  HudTokenList *token_list;
54
55
  gint num_results;
55
56
  guint refresh_id;
56
57
 
100
101
hud_query_refresh (HudQuery *query)
101
102
{
102
103
  guint max_usage = 0;
 
104
  guint64 start_time;
 
105
 
 
106
  start_time = g_get_monotonic_time ();
103
107
 
104
108
  g_ptr_array_set_size (query->results, 0);
105
109
 
106
110
  if (query->search_string[0] != '\0')
107
 
    hud_source_search (query->source, query->results, query->search_string);
 
111
    hud_source_search (query->source, query->results, query->token_list);
108
112
 
109
113
  g_ptr_array_foreach (query->results, hud_query_find_max_usage, &max_usage);
110
114
  g_ptr_array_sort_with_data (query->results, hud_query_compare_results, GINT_TO_POINTER (max_usage));
111
115
  if (query->results->len > query->num_results)
112
116
    g_ptr_array_set_size (query->results, query->num_results);
 
117
 
 
118
  g_debug ("query took %dus\n", (int) (g_get_monotonic_time () - start_time));
113
119
}
114
120
 
115
121
static gboolean
148
154
  hud_source_unuse (query->source);
149
155
 
150
156
  g_object_unref (query->source);
 
157
  hud_token_list_free (query->token_list);
151
158
  g_free (query->search_string);
152
159
  g_ptr_array_unref (query->results);
153
160
 
206
213
  query->source = g_object_ref (source);
207
214
  query->results = g_ptr_array_new_with_free_func (g_object_unref);
208
215
  query->search_string = g_strdup (search_string);
 
216
  query->token_list = hud_token_list_new_from_string (query->search_string);
209
217
  query->num_results = num_results;
210
218
 
211
219
  hud_source_use (query->source);