[notmuch] [PATCH 1/2] Convert notmuch_message_list_t in a doubly linked

meskio at sindominio.net meskio at sindominio.net
Tue Dec 8 01:41:31 PST 2009


From: Ruben Pollan <meskio at sindominio.net>

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



More information about the notmuch mailing list