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 DE4764196F0 for ; Sat, 20 Mar 2010 03:21:31 -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 4EZe0y+-JFrd for ; Sat, 20 Mar 2010 03:21:31 -0700 (PDT) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id 8E1A8431FC1 for ; Sat, 20 Mar 2010 03:21:28 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id 3358E262E3D; Sat, 20 Mar 2010 11:21:27 +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 xDkq1D1zhmB1; Sat, 20 Mar 2010 11:21:24 +0100 (CET) Received: from blackspot (heal.cauterized.net [89.140.131.167]) by flatline.sindominio.net (Postfix) with ESMTPA id A238A262E3B; Sat, 20 Mar 2010 11:21:21 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id 1085B8BDF7; Sat, 20 Mar 2010 11:24:34 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Date: Sat, 20 Mar 2010 11:23:21 +0100 Message-Id: <1269080605-5617-2-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 1/5] Convert notmuch_message_list_t in a doubly linked 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:32 -0000 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 db2b7a1..2a85774 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 d52d84d..3b3f0eb 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -349,11 +349,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 ec80f85..05d2c39 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.7.0