[tracker/journal: 6/21] libtracker-data: Avoid duplicating subject string in memory



commit 0c657455be1e504178f2dacbfdfab59e43a18fc3
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 |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index e90a963..114ebc1 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -71,7 +71,7 @@ struct _TrackerDataUpdateBuffer {
 };
 
 struct _TrackerDataUpdateBufferResource {
-	gchar *subject;
+	const gchar *subject;
 	gchar *new_subject;
 	gint id;
 	gboolean create;
@@ -711,7 +711,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);
@@ -1415,11 +1414,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;
@@ -1438,7 +1439,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]