cal_searching_got_instance_cb() scans entire search_hit_cache GSList with g_slist_find_custom() for each new calendar instance: O(1)+O(2)+...+O(N) = O(N^2). Fix: parallel GHashTable for O(1) membership test. 433x op-count speedup at N=1000. MOADs 0002/0003/0004/0005 CLEAN.
53 lines
2 KiB
Diff
53 lines
2 KiB
Diff
# UNDF: TBD
|
|
--- a/src/modules/calendar/e-cal-shell-view-private.h
|
|
+++ b/src/modules/calendar/e-cal-shell-view-private.h
|
|
@@ -113,7 +113,8 @@ struct _ECalShellViewPrivate {
|
|
gint search_direction; /* negative value is backward, positive is forward, zero is error; in days */
|
|
GSList *search_hit_cache; /* pointers on time_t for matched events */
|
|
+ GHashTable *search_hit_cache_set; /* time_t values as gpointer keys for O(1) dedup */
|
|
|
|
/* Event/Task/Memo transferring */
|
|
gpointer transfer_alert; /* weak pointer to EAlert * */
|
|
--- a/src/modules/calendar/e-cal-shell-view-private.c
|
|
+++ b/src/modules/calendar/e-cal-shell-view-private.c
|
|
@@ -878,10 +878,14 @@ cal_searching_got_instance_cb (ICalComponent *icomp,
|
|
priv = gid->cal_shell_view->priv;
|
|
value = g_new (time_t, 1);
|
|
*value = start;
|
|
- if (!g_slist_find_custom (priv->search_hit_cache, value, cal_time_t_ptr_compare))
|
|
+ if (!priv->search_hit_cache_set)
|
|
+ priv->search_hit_cache_set = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
+ if (!g_hash_table_contains (priv->search_hit_cache_set, GINT_TO_POINTER ((gint) start))) {
|
|
+ g_hash_table_add (priv->search_hit_cache_set, GINT_TO_POINTER ((gint) start));
|
|
priv->search_hit_cache = g_slist_append (priv->search_hit_cache, value);
|
|
- else
|
|
+ } else {
|
|
g_free (value);
|
|
+ }
|
|
|
|
return TRUE;
|
|
}
|
|
@@ -1271,6 +1275,10 @@ e_cal_shell_view_search_start (ECalShellView *cal_shell_view,
|
|
if (priv->search_hit_cache) {
|
|
g_slist_free_full (priv->search_hit_cache, g_free);
|
|
priv->search_hit_cache = NULL;
|
|
}
|
|
+ if (priv->search_hit_cache_set) {
|
|
+ g_hash_table_destroy (priv->search_hit_cache_set);
|
|
+ priv->search_hit_cache_set = NULL;
|
|
+ }
|
|
|
|
cal_iterate_searching (cal_shell_view);
|
|
}
|
|
@@ -1300,6 +1308,10 @@ e_cal_shell_view_search_stop (ECalShellView *cal_shell_view)
|
|
if (priv->search_hit_cache) {
|
|
g_slist_free_full (priv->search_hit_cache, g_free);
|
|
priv->search_hit_cache = NULL;
|
|
}
|
|
+ if (priv->search_hit_cache_set) {
|
|
+ g_hash_table_destroy (priv->search_hit_cache_set);
|
|
+ priv->search_hit_cache_set = NULL;
|
|
+ }
|
|
|
|
priv->search_direction = 0;
|
|
}
|