[PATCH 2/9] lib: private string map (associative array) API
[notmuch-archives.git] / f0 / 8074a21b9b0f253bcad98021c4e7906a508833
1 Return-Path: <meskio@sindominio.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 50E0A431FBD\r
6         for <notmuch@notmuchmail.org>; Tue,  8 Dec 2009 01:40:56 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id RZIys-qipQVd for <notmuch@notmuchmail.org>;\r
11         Tue,  8 Dec 2009 01:40:55 -0800 (PST)\r
12 Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26])\r
13         by olra.theworths.org (Postfix) with ESMTP id 7DBD3431FAE\r
14         for <notmuch@notmuchmail.org>; Tue,  8 Dec 2009 01:40:55 -0800 (PST)\r
15 Received: from localhost (localhost.localdomain [127.0.0.1])\r
16         by flatline.sindominio.net (Postfix) with ESMTP id 5D67A262583;\r
17         Tue,  8 Dec 2009 10:40:54 +0100 (CET)\r
18 X-Virus-Scanned: Debian amavisd-new at sindominio.net\r
19 Received: from flatline.sindominio.net ([127.0.0.1])\r
20         by localhost (flatline.sindominio.net [127.0.0.1]) (amavisd-new,\r
21         port 10024)\r
22         with ESMTP id 95Z-bDXMcjoV; Tue,  8 Dec 2009 10:40:51 +0100 (CET)\r
23 Received: from blackspot (rpollan-laptop.cern.ch [137.138.192.228])\r
24         by flatline.sindominio.net (Postfix) with ESMTPA id 4F42326257F;\r
25         Tue,  8 Dec 2009 10:40:51 +0100 (CET)\r
26 Received: by blackspot (Postfix, from userid 1000)\r
27         id D8A3D8BC3B; Tue,  8 Dec 2009 10:42:58 +0100 (CET)\r
28 From: meskio@sindominio.net\r
29 To: notmuch@notmuchmail.org\r
30 Date: Tue,  8 Dec 2009 10:41:31 +0100\r
31 Message-Id: <1260265292-12591-2-git-send-email-meskio@sindominio.net>\r
32 X-Mailer: git-send-email 1.6.5.4\r
33 In-Reply-To: <1260265292-12591-1-git-send-email-meskio@sindominio.net>\r
34 References: <20091126202347.GA16654@blackspot>\r
35         <1260265292-12591-1-git-send-email-meskio@sindominio.net>\r
36 Subject: [notmuch] [PATCH 1/2] Convert notmuch_message_list_t in a doubly\r
37         linked\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.12\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Tue, 08 Dec 2009 09:40:56 -0000\r
51 \r
52 From: Ruben Pollan <meskio@sindominio.net>\r
53 \r
54 The messages list now have pointers to previous nodes, so it is possible to\r
55 iterate backwards.\r
56 ---\r
57  lib/messages.c        |   18 +++++++++++++-----\r
58  lib/notmuch-private.h |    3 ++-\r
59  lib/thread.cc         |    4 ++--\r
60  3 files changed, 17 insertions(+), 8 deletions(-)\r
61 \r
62 diff --git a/lib/messages.c b/lib/messages.c\r
63 index aa92535..5414f87 100644\r
64 --- a/lib/messages.c\r
65 +++ b/lib/messages.c\r
66 @@ -37,20 +37,28 @@ _notmuch_message_list_create (const void *ctx)\r
67         return NULL;\r
68  \r
69      list->head = NULL;\r
70 -    list->tail = &list->head;\r
71 +    list->tail = NULL;\r
72  \r
73      return list;\r
74  }\r
75  \r
76 -/* Append 'node' (which can of course point to an arbitrarily long\r
77 - * list of nodes) to the end of 'list'.\r
78 +/* Append 'node' to the end of 'list'.\r
79   */\r
80  void\r
81  _notmuch_message_list_append (notmuch_message_list_t *list,\r
82                               notmuch_message_node_t *node)\r
83  {\r
84 -    *(list->tail) = node;\r
85 -    list->tail = &node->next;\r
86 +    node->prev = list->tail;\r
87 +    if (list->head)\r
88 +    {\r
89 +        list->tail->next = node;\r
90 +    }\r
91 +    else\r
92 +    {\r
93 +        list->head = node;\r
94 +        list->tail = node;\r
95 +    }\r
96 +    list->tail = node;\r
97  }\r
98  \r
99  /* Allocate a new node for 'message' and append it to the end of\r
100 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
101 index 0c340a7..133ed0e 100644\r
102 --- a/lib/notmuch-private.h\r
103 +++ b/lib/notmuch-private.h\r
104 @@ -285,11 +285,12 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,\r
105  typedef struct _notmuch_message_node {\r
106      notmuch_message_t *message;\r
107      struct _notmuch_message_node *next;\r
108 +    struct _notmuch_message_node *prev;\r
109  } notmuch_message_node_t;\r
110  \r
111  typedef struct _notmuch_message_list {\r
112      notmuch_message_node_t *head;\r
113 -    notmuch_message_node_t **tail;\r
114 +    notmuch_message_node_t *tail;\r
115  } notmuch_message_list_t;\r
116  \r
117  /* There's a rumor that there's an alternate struct _notmuch_messages\r
118 diff --git a/lib/thread.cc b/lib/thread.cc\r
119 index 321937b..24dbe2c 100644\r
120 --- a/lib/thread.cc\r
121 +++ b/lib/thread.cc\r
122 @@ -169,8 +169,8 @@ _resolve_thread_relationships (unused (notmuch_thread_t *thread))\r
123                                           (void **) &parent))\r
124         {\r
125             *prev = node->next;\r
126 -           if (thread->message_list->tail == &node->next)\r
127 -               thread->message_list->tail = prev;\r
128 +           if (thread->message_list->tail == node)\r
129 +               thread->message_list->tail = node->prev;\r
130             node->next = NULL;\r
131             _notmuch_message_add_reply (parent, node);\r
132         } else {\r
133 -- \r
134 1.6.5.4\r
135 \r