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 50E0A431FBD for ; Tue, 8 Dec 2009 01:40:56 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 RZIys-qipQVd for ; Tue, 8 Dec 2009 01:40:55 -0800 (PST) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id 7DBD3431FAE for ; Tue, 8 Dec 2009 01:40:55 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id 5D67A262583; Tue, 8 Dec 2009 10:40:54 +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 95Z-bDXMcjoV; Tue, 8 Dec 2009 10:40:51 +0100 (CET) Received: from blackspot (rpollan-laptop.cern.ch [137.138.192.228]) by flatline.sindominio.net (Postfix) with ESMTPA id 4F42326257F; Tue, 8 Dec 2009 10:40:51 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id D8A3D8BC3B; Tue, 8 Dec 2009 10:42:58 +0100 (CET) From: meskio@sindominio.net To: notmuch@notmuchmail.org Date: Tue, 8 Dec 2009 10:41:31 +0100 Message-Id: <1260265292-12591-2-git-send-email-meskio@sindominio.net> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <1260265292-12591-1-git-send-email-meskio@sindominio.net> References: <20091126202347.GA16654@blackspot> <1260265292-12591-1-git-send-email-meskio@sindominio.net> Subject: [PATCH 1/2] Convert notmuch_message_list_t in a doubly linked X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Tue, 08 Dec 2009 09:40:56 -0000 From: Ruben Pollan The messages list now have pointers to previous nodes, so it is possible to iterate backwards. --- lib/messages.c | 18 +++++++++++++----- lib/notmuch-private.h | 3 ++- lib/thread.cc | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/messages.c b/lib/messages.c index aa92535..5414f87 100644 --- a/lib/messages.c +++ b/lib/messages.c @@ -37,20 +37,28 @@ _notmuch_message_list_create (const void *ctx) return NULL; list->head = NULL; - list->tail = &list->head; + list->tail = NULL; return list; } -/* Append 'node' (which can of course point to an arbitrarily long - * list of nodes) to the end of 'list'. +/* Append 'node' to the end of 'list'. */ void _notmuch_message_list_append (notmuch_message_list_t *list, notmuch_message_node_t *node) { - *(list->tail) = node; - list->tail = &node->next; + node->prev = list->tail; + if (list->head) + { + list->tail->next = node; + } + else + { + list->head = node; + list->tail = node; + } + list->tail = node; } /* Allocate a new node for 'message' and append it to the end of diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 0c340a7..133ed0e 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -285,11 +285,12 @@ notmuch_message_file_get_header (notmuch_message_file_t *message, typedef struct _notmuch_message_node { notmuch_message_t *message; struct _notmuch_message_node *next; + struct _notmuch_message_node *prev; } notmuch_message_node_t; typedef struct _notmuch_message_list { notmuch_message_node_t *head; - notmuch_message_node_t **tail; + notmuch_message_node_t *tail; } notmuch_message_list_t; /* There's a rumor that there's an alternate struct _notmuch_messages diff --git a/lib/thread.cc b/lib/thread.cc index 321937b..24dbe2c 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -169,8 +169,8 @@ _resolve_thread_relationships (unused (notmuch_thread_t *thread)) (void **) &parent)) { *prev = node->next; - if (thread->message_list->tail == &node->next) - thread->message_list->tail = prev; + if (thread->message_list->tail == node) + thread->message_list->tail = node->prev; node->next = NULL; _notmuch_message_add_reply (parent, node); } else { -- 1.6.5.4