[tracker/rss-enclosures] tracker-store: Memory optimization in class signals, avoid duplicate strings



commit 5be424065afb06d56863a729b2634e370e892f72
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Jun 11 16:31:10 2010 +0200

    tracker-store: Memory optimization in class signals, avoid duplicate strings

 src/tracker-store/tracker-events.c |   21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)
---
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index fed1377..5bfc215 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -30,6 +30,7 @@
 typedef struct {
 	GHashTable *allowances;
 	GArray *events;
+	GStringChunk *chunk;
 } EventsPrivate;
 
 static EventsPrivate *private;
@@ -70,10 +71,14 @@ prepare_event_for_rdf_type (EventsPrivate *private,
 		private->events = g_array_new (TRUE, FALSE, sizeof (TrackerEvent));
 	}
 
+	if (!private->chunk) {
+		private->chunk = g_string_chunk_new (strlen (uri) + 10);
+	}
+
 	event.type = type;
 	event.class = rdf_class;
 	event.predicate = tracker_ontologies_get_property_by_uri (predicate);
-	event.subject = g_strdup (uri);
+	event.subject = g_string_chunk_insert_const (private->chunk, uri);
 
 	g_array_append_val (private->events, event);
 }
@@ -111,25 +116,15 @@ tracker_events_insert (const gchar *uri,
 	}
 }
 
-static void
-tracker_event_destroy (TrackerEvent *event)
-{
-	g_free (event->subject);
-}
-
 void
 tracker_events_reset (void)
 {
-	guint i;
-
 	g_return_if_fail (private != NULL);
 
 	if (private->events) {
-		for (i = 0; i < private->events->len; i++) {
-			tracker_event_destroy (&g_array_index (private->events, TrackerEvent, i));
-		}
 		g_array_free (private->events, TRUE);
-
+		g_string_chunk_free (private->chunk);
+		private->chunk = NULL;
 		private->events = NULL;
 	}
 }



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