[tracker/miner-web-review] libtracker-data: Avoid duplicating subject string in memory



commit 09c373604944f3e3ff9baa31da1e11e18ed03653
Author: Jürg Billeter <j bitron ch>
Date:   Fri Mar 12 11:49:47 2010 +0100

    libtracker-data: Avoid duplicating subject string in memory

 src/libtracker-data/tracker-data-update.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index ffd92f6..e311327 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -71,7 +71,8 @@ struct _TrackerDataUpdateBuffer {
 };
 
 struct _TrackerDataUpdateBufferResource {
-	gchar *subject;
+	const gchar *subject;
+	gchar *new_subject;
 	gint id;
 	gboolean create;
 	gboolean fts_updated;
@@ -689,7 +690,6 @@ static void resource_buffer_free (TrackerDataUpdateBufferResource *resource)
 {
 	g_hash_table_unref (resource->predicates);
 	g_hash_table_unref (resource->tables);
-	g_free (resource->subject);
 	resource->subject = NULL;
 
 	g_ptr_array_free (resource->types, TRUE);
@@ -1393,11 +1393,13 @@ resource_buffer_switch (const gchar *graph,
 
 	if (resource_buffer == NULL) {
 		GValue gvalue = { 0 };
+		gchar *subject_dup = NULL;
 
 		/* subject not yet in cache, retrieve or create ID */
 		resource_buffer = g_slice_new0 (TrackerDataUpdateBufferResource);
 		if (subject != NULL) {
-			resource_buffer->subject = g_strdup (subject);
+			subject_dup = g_strdup (subject);
+			resource_buffer->subject = subject_dup;
 		}
 		if (subject_id > 0) {
 			resource_buffer->id = subject_id;
@@ -1416,7 +1418,7 @@ resource_buffer_switch (const gchar *graph,
 		if (in_journal_replay) {
 			g_hash_table_insert (update_buffer.resources_by_id, GINT_TO_POINTER (subject_id), resource_buffer);
 		} else {
-			g_hash_table_insert (update_buffer.resources, g_strdup (subject), resource_buffer);
+			g_hash_table_insert (update_buffer.resources, subject_dup, resource_buffer);
 
 			if (graph != NULL) {
 				graph_id = ensure_resource_id (graph, NULL);



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