tracker r1620 - in branches/xesam-support: . src/trackerd



Author: pvanhoof
Date: Tue Jun 10 10:08:52 2008
New Revision: 1620
URL: http://svn.gnome.org/viewvc/tracker?rev=1620&view=rev

Log:
2008-06-10  Philip Van Hoof  <pvanhoof gnome org>

        * src/trackerd/tracker-xesam-live-search.c: Preserving the sort order
        in get_hit_data



Modified:
   branches/xesam-support/ChangeLog
   branches/xesam-support/src/trackerd/tracker-xesam-live-search.c

Modified: branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-live-search.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-live-search.c	Tue Jun 10 10:08:52 2008
@@ -547,12 +547,45 @@
 	return SANE_TYPE;
 }
 
+
+typedef struct {
+	gint key;
+	gpointer value;
+} OneRow;
+
+static inline gpointer 
+rows_lookup (GPtrArray *rows, gint key)
+{
+	guint i;
+	gpointer value = NULL;
+
+	for (i = 0; i < rows->len; i++) {
+		OneRow *row = g_ptr_array_index (rows, i);
+		if (row->key == key) {
+			value = row->value;
+			break;
+		}
+	}
+	return value;
+}
+
+static inline void
+rows_destroy (GPtrArray *rows)
+{
+	guint i;
+
+	for (i = 0; i < rows->len; i++) {
+		g_slice_free (OneRow, g_ptr_array_index (rows, i));
+	}
+}
+
 static inline void
-foreach_row_put_in_result (gpointer key, gpointer value, gpointer user_data)
+rows_insert (GPtrArray *rows, gint key, gpointer value)
 {
-	GPtrArray *result = user_data;
-	GPtrArray *row = value;
-	g_ptr_array_add (result, row);
+	OneRow *row = g_slice_new (OneRow);
+	row->key = key;
+	row->value = value;
+	g_ptr_array_add (rows, row);
 }
 
 /**
@@ -584,8 +617,9 @@
 	      gint                     field_count)
 {
 	GPtrArray  *result = g_ptr_array_new ();
-	GHashTable *rows = g_hash_table_new (g_int_hash, g_int_equal);
+	GPtrArray  *rows = g_ptr_array_new ();
 	gboolean    valid = TRUE;
+	guint       i;
 
 	while (valid) {
 		gint        column;
@@ -620,7 +654,12 @@
 		 **/
 
 		key = g_value_get_int (&value_in);
-		row = g_hash_table_lookup (rows, &key);
+
+		/* Think before rewriting this using a GHashTable: A GHashTable
+		 * doesn't preserve the sort order. The sort order is indeed
+		 * significant for the Xesam spec. */
+
+		row = rows_lookup (rows, key);
 
 		if (!row) {
 			row = g_ptr_array_new ();
@@ -706,16 +745,19 @@
 
 
 		if (insert) {
-			g_hash_table_insert (rows, &key, row);
-		} else {
-			g_hash_table_replace (rows, &key, row);
+			rows_insert (rows, key, row);
 		}
 
 		valid = tracker_db_result_set_iter_next (result_set);
 	}
 
-	g_hash_table_foreach (rows, foreach_row_put_in_result, result);
-	g_hash_table_destroy (rows);
+	for (i = 0; i < rows->len; i++) {
+		OneRow *one = g_ptr_array_index (rows, i);
+		GPtrArray *row = one->value;
+		g_ptr_array_add (result, row);
+	}
+
+	rows_destroy (rows);
 
 	*hit_data = result;
 }



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