[notmuch] [PATCH 1/2] Move the logic of threads iterator out of 'valid'

Ruben Pollan meskio at sindominio.net
Sun Mar 21 14:32:32 PDT 2010


The logic of notmuch_threads_move_to_next iterator was on
notmuch_threads_valid function. Now notmuch_threads_valid just check if
the iterator is valid and is notmuch_threads_move_to_next wich actually
update the iterator.
---
 lib/query.cc |   54 ++++++++++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/lib/query.cc b/lib/query.cc
index 9266d35..514a156 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -233,6 +233,7 @@ notmuch_threads_t *
 notmuch_query_search_threads (notmuch_query_t *query)
 {
     notmuch_threads_t *threads;
+    notmuch_message_t *message;
 
     threads = talloc (query, notmuch_threads_t);
     if (threads == NULL)
@@ -243,8 +244,17 @@ notmuch_query_search_threads (notmuch_query_t *query)
 					      free, NULL);
 
     threads->messages = notmuch_query_search_messages (query);
+    if (!notmuch_messages_valid (threads->messages))
+    {
+        threads->thread_id = NULL;
+        return threads;
+    }
 
-    threads->thread_id = NULL;
+    message = notmuch_messages_get (threads->messages);
+    threads->thread_id = notmuch_message_get_thread_id (message);
+    g_hash_table_insert (threads->threads,
+                         xstrdup (threads->thread_id),
+                         NULL);
 
     talloc_set_destructor (threads, _notmuch_threads_destructor);
 
@@ -260,10 +270,25 @@ notmuch_query_destroy (notmuch_query_t *query)
 notmuch_bool_t
 notmuch_threads_valid (notmuch_threads_t *threads)
 {
-    notmuch_message_t *message;
+    return (threads->thread_id != NULL);
+}
+
+notmuch_thread_t *
+notmuch_threads_get (notmuch_threads_t *threads)
+{
+    if (! notmuch_threads_valid (threads))
+	return NULL;
+
+    return _notmuch_thread_create (threads->query,
+				   threads->query->notmuch,
+				   threads->thread_id,
+				   threads->query->query_string);
+}
 
-    if (threads->thread_id)
-	return TRUE;
+void
+notmuch_threads_move_to_next (notmuch_threads_t *threads)
+{
+    notmuch_message_t *message;
 
     while (notmuch_messages_valid (threads->messages))
     {
@@ -278,32 +303,13 @@ notmuch_threads_valid (notmuch_threads_t *threads)
 	    g_hash_table_insert (threads->threads,
 				 xstrdup (threads->thread_id), NULL);
 	    notmuch_messages_move_to_next (threads->messages);
-	    return TRUE;
+	    return;
 	}
 
 	notmuch_messages_move_to_next (threads->messages);
     }
 
     threads->thread_id = NULL;
-    return FALSE;
-}
-
-notmuch_thread_t *
-notmuch_threads_get (notmuch_threads_t *threads)
-{
-    if (! notmuch_threads_valid (threads))
-	return NULL;
-
-    return _notmuch_thread_create (threads->query,
-				   threads->query->notmuch,
-				   threads->thread_id,
-				   threads->query->query_string);
-}
-
-void
-notmuch_threads_move_to_next (notmuch_threads_t *threads)
-{
-    threads->thread_id = NULL;
 }
 
 void
-- 
1.7.0



More information about the notmuch mailing list