From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 59BD9431FAF for ; Sat, 24 Nov 2012 20:57:21 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 p-g33t5ItADr for ; Sat, 24 Nov 2012 20:57:20 -0800 (PST) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 8F525431FBF for ; Sat, 24 Nov 2012 20:57:19 -0800 (PST) X-AuditID: 12074424-b7fce6d000000925-3c-50b1a52e6a56 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id C0.DA.02341.E25A1B05; Sat, 24 Nov 2012 23:57:18 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qAP4vHTg018857; Sat, 24 Nov 2012 23:57:17 -0500 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qAP4vEDW000082 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 24 Nov 2012 23:57:16 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TcUHJ-0003Zn-Ss; Sat, 24 Nov 2012 23:57:13 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 2/6] lib: Separate list of all messages from top-level messages Date: Sat, 24 Nov 2012 23:57:03 -0500 Message-Id: <1353819427-13182-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1353819427-13182-1-git-send-email-amdragon@mit.edu> References: <1353819427-13182-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrau3dGOAweR/shar5/JYXL85k9mB yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgytjYNY294L9cxarT95gaGF9JdDFyckgImEis +HqDDcIWk7hwbz2QzcUhJLCPUeLEjrPsEM4GRolHZ86zQjiPmCS2nrkFVTaXUWJz81kWkH42 AQ2JbfuXM4LYIgLSEjvvzmYFsZkFHCU+718EtkNYwF/i/r4msDiLgKrEyU07wWxeAQeJuXd2 M0LcoSjR/WwCUD0HBydQb+NeOZCwEFDJrX+TmCcw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiX l1qka66Xm1mil5pSuokRFEjsLio7GJsPKR1iFOBgVOLhvZG4MUCINbGsuDL3EKMkB5OSKG/m IqAQX1J+SmVGYnFGfFFpTmrxIUYJDmYlEV5rVaAcb0piZVVqUT5MSpqDRUmc93rKTX8hgfTE ktTs1NSC1CKYrAwHh5IEr8gSoEbBotT01Iq0zJwShDQTByfIcB6g4aIgNbzFBYm5xZnpEPlT jIpS4rzmIAkBkERGaR5cLyzSXzGKA70izOsAUsUDTBJw3a+ABjMBDX46ex3I4JJEhJRUA2N0 jJWA01Nd8wdnjjdWcTyZYXwo/NmhHB2WSSfqwtv2XvmqGyRiFpUvqiX5NeN8z9+61vid039c lXoUGp+5OMWOXXBWhZ/lXRaZKfUTWOeUd+yL4Vv088FH7irpc/4ec80FUm5ufriroEpi5X8V G6vURTMX3H66fsHXgJpj25quWLfrPWTic1FiKc5INNRiLipOBACvrW8czwIAAA== 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, 25 Nov 2012 04:57:21 -0000 Previously, thread.cc built up a list of all messages, then proceeded to tear it apart to transform it into a list of top-level messages. Now we simply build a new list of top-level messages. This simplifies the interface to _notmuch_message_add_reply, eliminates the pointer acrobatics from _resolve_thread_relationships, and will enable us to do things with the list of all messages in the following patches. --- lib/message.cc | 4 ++-- lib/notmuch-private.h | 2 +- lib/thread.cc | 29 ++++++++++++++--------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 978de06..171c580 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -462,9 +462,9 @@ notmuch_message_get_thread_id (notmuch_message_t *message) void _notmuch_message_add_reply (notmuch_message_t *message, - notmuch_message_node_t *reply) + notmuch_message_t *reply) { - _notmuch_message_list_append (message->replies, reply); + _notmuch_message_list_add_message (message->replies, reply); } notmuch_messages_t * diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 7a409f5..c054a0e 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -462,7 +462,7 @@ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids, void _notmuch_message_add_reply (notmuch_message_t *message, - notmuch_message_node_t *reply); + notmuch_message_t *reply); /* sha1.c */ diff --git a/lib/thread.cc b/lib/thread.cc index aed87b1..45a7d1d 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -35,7 +35,11 @@ struct visible _notmuch_thread { char *authors; GHashTable *tags; + /* All messages, oldest first. */ notmuch_message_list_t *message_list; + /* Top-level messages, oldest first. */ + notmuch_message_list_t *toplevel_list; + GHashTable *message_hash; int total_messages; int matched_messages; @@ -345,29 +349,22 @@ _thread_add_matched_message (notmuch_thread_t *thread, } static void -_resolve_thread_relationships (unused (notmuch_thread_t *thread)) +_resolve_thread_relationships (notmuch_thread_t *thread) { - notmuch_message_node_t **prev, *node; + notmuch_message_node_t *node; notmuch_message_t *message, *parent; const char *in_reply_to; - prev = &thread->message_list->head; - while ((node = *prev)) { + for (node = thread->message_list->head; node; node = node->next) { message = node->message; in_reply_to = _notmuch_message_get_in_reply_to (message); if (in_reply_to && strlen (in_reply_to) && g_hash_table_lookup_extended (thread->message_hash, in_reply_to, NULL, (void **) &parent)) - { - *prev = node->next; - if (thread->message_list->tail == &node->next) - thread->message_list->tail = prev; - node->next = NULL; - _notmuch_message_add_reply (parent, node); - } else { - prev = &((*prev)->next); - } + _notmuch_message_add_reply (parent, message); + else + _notmuch_message_list_add_message (thread->toplevel_list, message); } /* XXX: After scanning through the entire list looking for parents @@ -451,7 +448,9 @@ _notmuch_thread_create (void *ctx, free, NULL); thread->message_list = _notmuch_message_list_create (thread); - if (unlikely (thread->message_list == NULL)) { + thread->toplevel_list = _notmuch_message_list_create (thread); + if (unlikely (thread->message_list == NULL || + thread->toplevel_list == NULL)) { thread = NULL; goto DONE; } @@ -506,7 +505,7 @@ _notmuch_thread_create (void *ctx, notmuch_messages_t * notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread) { - return _notmuch_messages_create (thread->message_list); + return _notmuch_messages_create (thread->toplevel_list); } const char * -- 1.7.10.4