[tracker] Replaced a GPtrArray with a GHashTable, constant lookup speed
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Replaced a GPtrArray with a GHashTable, constant lookup speed
- Date: Mon, 10 Aug 2009 12:16:53 +0000 (UTC)
commit 1f98111f3771cef24370e0e8b2b51fcf4f61882d
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Aug 10 14:16:11 2009 +0200
Replaced a GPtrArray with a GHashTable, constant lookup speed
src/tracker-store/tracker-events.c | 37 ++++++++++++++---------------------
1 files changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index b52acfa..9d84812 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -29,10 +29,16 @@
typedef struct {
- GPtrArray *allowances;
+ GHashTable *allowances;
GPtrArray *events;
} EventsPrivate;
+typedef struct {
+ const gchar *uri;
+ const gchar *predicate;
+ TrackerDBusEventsType type;
+} PreparableEvent;
+
static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
static void
@@ -43,31 +49,16 @@ tracker_events_add_allow (const gchar *rdf_class)
private = g_static_private_get (&private_key);
g_return_if_fail (private != NULL);
- g_ptr_array_add (private->allowances, g_strdup (rdf_class));
+ g_hash_table_insert (private->allowances, g_strdup (rdf_class),
+ GINT_TO_POINTER (TRUE));
}
static gboolean
is_allowed (EventsPrivate *private, const gchar *rdf_class)
{
- guint i;
- gboolean found = FALSE;
-
- for (i = 0; i < private->allowances->len; i++) {
- if (g_strcmp0 (rdf_class, private->allowances->pdata[i]) == 0) {
- found = TRUE;
- break;
- }
- }
-
- return found;
+ return (g_hash_table_lookup (private->allowances, rdf_class) != NULL) ? TRUE : FALSE;
}
-typedef struct {
- const gchar *uri;
- const gchar *predicate;
- TrackerDBusEventsType type;
-} PreparableEvent;
-
static void
prepare_event_for_rdf_types (gpointer data, gpointer user_data)
{
@@ -179,8 +170,7 @@ tracker_events_get_pending (void)
static void
free_private (EventsPrivate *private)
{
- g_ptr_array_foreach (private->allowances, (GFunc)g_free, NULL);
- g_ptr_array_free (private->allowances, TRUE);
+ g_hash_table_unref (private->allowances);
g_free (private);
}
@@ -197,7 +187,10 @@ tracker_events_init (TrackerNotifyClassGetter callback)
private,
(GDestroyNotify) free_private);
- private->allowances = g_ptr_array_new ();
+ private->allowances = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) NULL);
+
private->events = NULL;
if (!callback) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]