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 9ACAF4196F2 for ; Sun, 21 Mar 2010 14:30:20 -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 uGMrN-Ivr3s6 for ; Sun, 21 Mar 2010 14:30:19 -0700 (PDT) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id EE37B431FC1 for ; Sun, 21 Mar 2010 14:30:12 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id 1E966348093; Sun, 21 Mar 2010 22:30:12 +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 05IfKiPJPeWe; Sun, 21 Mar 2010 22:29:54 +0100 (CET) Received: from blackspot (heal.cauterized.net [89.140.131.167]) by flatline.sindominio.net (Postfix) with ESMTPA id EC32C348046; Sun, 21 Mar 2010 22:29:06 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id 7093C8BDFC; Sun, 21 Mar 2010 22:32:39 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Date: Sun, 21 Mar 2010 22:32:32 +0100 Message-Id: <1269207153-3687-2-git-send-email-meskio@sindominio.net> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1269080605-5617-1-git-send-email-meskio@sindominio.net> References: <1269080605-5617-1-git-send-email-meskio@sindominio.net> Subject: [notmuch] [PATCH 1/2] 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: Sun, 21 Mar 2010 21:30:20 -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 | 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