Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id BBE46414BBF for ; Sat, 20 Mar 2010 03:21:57 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OXGae9Lxykvr for ; Sat, 20 Mar 2010 03:21:56 -0700 (PDT) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id D518D41733B for ; Sat, 20 Mar 2010 03:21:55 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id 0E421262E3E; Sat, 20 Mar 2010 11:21:55 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at sindominio.net Received: from flatline.sindominio.net ([127.0.0.1]) by localhost (flatline.sindominio.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GXC1uBHjRNEL; Sat, 20 Mar 2010 11:21:50 +0100 (CET) Received: from blackspot (heal.cauterized.net [89.140.131.167]) by flatline.sindominio.net (Postfix) with ESMTPA id 0B9BB262E3B; Sat, 20 Mar 2010 11:21:43 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id B1AB18BDFD; Sat, 20 Mar 2010 11:24:53 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Date: Sat, 20 Mar 2010 11:23:23 +0100 Message-Id: <1269080605-5617-4-git-send-email-meskio@sindominio.net> X-Mailer: git-send-email 1.7.0 In-Reply-To: <873a09jt2t.fsf@yoom.home.cworth.org> References: <873a09jt2t.fsf@yoom.home.cworth.org> Subject: [notmuch] [PATCH 3/5] Move the logic of threads iterator out of 'valid' X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Mar 2010 10:21:57 -0000 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