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