[notmuch] [PATCH 3/5] Move the logic of threads iterator out of 'valid'

Ruben Pollan meskio at sindominio.net
Sat Mar 20 03:23:23 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 |   47 ++++++++++++++++++++++++-----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/lib/query.cc b/lib/query.cc
index 970c35a..44950c1 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -285,6 +285,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)
@@ -296,7 +297,10 @@ notmuch_query_search_threads (notmuch_query_t *query)
 
     threads->messages = notmuch_query_search_messages (query);
 
-    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);
 
@@ -312,10 +316,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);
+}
 
-    if (threads->thread_id)
-	return TRUE;
+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)
+{
+    notmuch_message_t *message;
 
     while (notmuch_messages_valid (threads->messages))
     {
@@ -330,33 +349,15 @@ 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
 notmuch_threads_destroy (notmuch_threads_t *threads)
-- 
1.7.0



More information about the notmuch mailing list