[tracker] tracker-store: Reuse string chunk during event handling



commit bb9ce97a337e47d487604fbb5e31fdd760786bfa
Author: Jürg Billeter <j bitron ch>
Date:   Wed Jun 30 11:16:30 2010 +0200

    tracker-store: Reuse string chunk during event handling

 src/tracker-store/tracker-events.c         |    2 +-
 src/tracker-store/tracker-resource-class.c |   27 +++++++--------------------
 src/tracker-store/tracker-resources.c      |    3 +++
 3 files changed, 11 insertions(+), 21 deletions(-)
---
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index 5bfc215..4359659 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -72,7 +72,7 @@ prepare_event_for_rdf_type (EventsPrivate *private,
 	}
 
 	if (!private->chunk) {
-		private->chunk = g_string_chunk_new (strlen (uri) + 10);
+		private->chunk = g_string_chunk_new (4096);
 	}
 
 	event.type = type;
diff --git a/src/tracker-store/tracker-resource-class.c b/src/tracker-store/tracker-resource-class.c
index 666102b..834b13c 100644
--- a/src/tracker-store/tracker-resource-class.c
+++ b/src/tracker-store/tracker-resource-class.c
@@ -43,7 +43,6 @@ typedef struct {
 	gchar *dbus_path;
 	GHashTable *adds_table, *ups_table, *dels_table;
 	GArray *ups;
-	GStringChunk *changed_strings;
 	DBusConnection *connection;
 } TrackerResourceClassPrivate;
 
@@ -236,11 +235,6 @@ tracker_resource_class_emit_events (TrackerResourceClass  *object)
 		priv->dels_table = NULL;
 	}
 
-	if (priv->changed_strings) {
-		g_string_chunk_free (priv->changed_strings);
-		priv->changed_strings = NULL;
-	}
-
 }
 
 
@@ -303,43 +297,36 @@ tracker_resource_class_add_event (TrackerResourceClass  *object,
 
 	priv = TRACKER_RESOURCE_CLASS_GET_PRIVATE (object);
 
-	if (!priv->changed_strings) {
-		/* allocate in chunks of 4K */
-		priv->changed_strings = g_string_chunk_new (4096);
-	}
+	/* We reuse the strings we get from tracker-events without copying
+	   to keep memory usage low. Code in tracker-resources.c guarantees
+	   that they are not freed too early. */
 
 	switch (type) {
 	case TRACKER_DBUS_EVENTS_TYPE_ADD:
 
-		n_uri = g_string_chunk_insert_const (priv->changed_strings, uri);
-
 		if (!priv->adds_table) {
 			priv->adds_table = g_hash_table_new (NULL, NULL);
 		}
 
-		g_hash_table_insert (priv->adds_table, n_uri, GINT_TO_POINTER (TRUE));
+		g_hash_table_insert (priv->adds_table, uri, GINT_TO_POINTER (TRUE));
 		break;
 	case TRACKER_DBUS_EVENTS_TYPE_UPDATE:
 
-		n_uri = g_string_chunk_insert_const (priv->changed_strings, uri);
-
 		if (!priv->ups_table) {
 			priv->ups_table = g_hash_table_new (NULL, NULL);
 		}
 
-		hash_key = (gpointer) ((gsize) n_uri ^ (gsize) predicate);
+		hash_key = (gpointer) ((gsize) uri ^ (gsize) predicate);
 
-		g_hash_table_insert (priv->ups_table, hash_key, n_uri);
+		g_hash_table_insert (priv->ups_table, hash_key, uri);
 		break;
 	case TRACKER_DBUS_EVENTS_TYPE_DELETE:
 
-		n_uri = g_string_chunk_insert_const (priv->changed_strings, uri);
-
 		if (!priv->dels_table) {
 			priv->dels_table = g_hash_table_new (NULL, NULL);
 		}
 
-		g_hash_table_insert (priv->dels_table, n_uri, GINT_TO_POINTER (TRUE));
+		g_hash_table_insert (priv->dels_table, uri, GINT_TO_POINTER (TRUE));
 		break;
 	default:
 		break;
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 43f173f..70e051b 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -567,6 +567,9 @@ on_statements_committed (gpointer user_data)
 	/* Class signals feature */
 	events = tracker_events_get_pending ();
 
+	/* Do not call tracker_events_reset before calling tracker_resource_class_emit_events
+	   as we're reusing the same strings without copies */
+
 	if (events) {
 		GSList *event_sources, *l;
 		guint i;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]