1 Return-Path: <amdragon@mit.edu>
\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 74CA9431FD0
\r
6 for <notmuch@notmuchmail.org>; Wed, 8 Dec 2010 14:01:56 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id F4wAxNBzpSu9 for <notmuch@notmuchmail.org>;
\r
16 Wed, 8 Dec 2010 14:01:55 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id CE4E5431FB5
\r
20 for <notmuch@notmuchmail.org>; Wed, 8 Dec 2010 14:01:55 -0800 (PST)
\r
21 X-AuditID: 1209190d-b7cacae000000a14-5f-4d0000538ba5
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-2.mit.edu (Symantec Brightmail Gateway) with
\r
24 SMTP id 2E.4D.02580.350000D4; Wed, 8 Dec 2010 17:01:55 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id oB8M1sSZ021056;
\r
27 Wed, 8 Dec 2010 17:01:55 -0500
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id oB8M1rJn019459
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Wed, 8 Dec 2010 17:01:54 -0500 (EST)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1PQS5B-0001iD-DC; Wed, 08 Dec 2010 17:01:53 -0500
\r
37 Date: Wed, 8 Dec 2010 17:01:53 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Carl Worth <cworth@cworth.org>
\r
40 Subject: [PATCH] Various small clean-ups to doc ID set code.
\r
41 Message-ID: <20101208220153.GT2447@mit.edu>
\r
42 References: <20101117192826.GU2439@mit.edu>
\r
43 <874oap5aek.fsf@yoom.home.cworth.org>
\r
44 <20101208215844.GS2447@mit.edu>
\r
46 Content-Type: text/plain; charset=us-ascii
\r
47 Content-Disposition: inline
\r
48 In-Reply-To: <20101208215844.GS2447@mit.edu>
\r
49 User-Agent: Mutt/1.5.20 (2009-06-14)
\r
50 X-Brightmail-Tracker: AAAAAA==
\r
51 Cc: notmuch@notmuchmail.org
\r
52 X-BeenThere: notmuch@notmuchmail.org
\r
53 X-Mailman-Version: 2.1.13
\r
55 List-Id: "Use and development of the notmuch mail system."
\r
56 <notmuch.notmuchmail.org>
\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
60 List-Post: <mailto:notmuch@notmuchmail.org>
\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
64 X-List-Received-Date: Wed, 08 Dec 2010 22:01:56 -0000
\r
66 Remove the repeated "sizeof (doc_ids->bitmap[0])" that bothered cworth
\r
67 by instead defining macros to compute the word and bit offset of a
\r
68 given bit in the bitmap.
\r
70 Don't require the caller of _notmuch_doc_id_set_init to pass in a
\r
71 correct bound; instead compute it from the array. This simplifies the
\r
72 caller and makes this interface easier to use correctly.
\r
74 lib/query.cc | 37 +++++++++++++++++++------------------
\r
75 1 files changed, 19 insertions(+), 18 deletions(-)
\r
77 diff --git a/lib/query.cc b/lib/query.cc
\r
78 index c7ae4ee..3b76dc5 100644
\r
81 @@ -38,9 +38,12 @@ typedef struct _notmuch_mset_messages {
\r
83 struct _notmuch_doc_id_set {
\r
84 unsigned int *bitmap;
\r
85 - unsigned int bound;
\r
89 +#define BITMAP_WORD(bit) ((bit) / sizeof (unsigned int))
\r
90 +#define BITMAP_BIT(bit) ((bit) % sizeof (unsigned int))
\r
92 struct _notmuch_threads {
\r
93 notmuch_query_t *query;
\r
95 @@ -257,22 +260,24 @@ _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages)
\r
96 static notmuch_bool_t
\r
97 _notmuch_doc_id_set_init (void *ctx,
\r
98 notmuch_doc_id_set_t *doc_ids,
\r
99 - GArray *arr, unsigned int bound)
\r
102 - size_t count = (bound + sizeof (doc_ids->bitmap[0]) - 1) /
\r
103 - sizeof (doc_ids->bitmap[0]);
\r
104 - unsigned int *bitmap = talloc_zero_array (ctx, unsigned int, count);
\r
105 + unsigned int max = 0;
\r
106 + unsigned int *bitmap;
\r
108 + for (unsigned int i = 0; i < arr->len; i++)
\r
109 + max = MAX(max, g_array_index (arr, unsigned int, i));
\r
110 + bitmap = talloc_zero_array (ctx, unsigned int, 1 + max / sizeof (*bitmap));
\r
112 if (bitmap == NULL)
\r
115 doc_ids->bitmap = bitmap;
\r
116 - doc_ids->bound = bound;
\r
117 + doc_ids->max = max;
\r
119 for (unsigned int i = 0; i < arr->len; i++) {
\r
120 - unsigned int doc_id = g_array_index(arr, unsigned int, i);
\r
121 - bitmap[doc_id / sizeof (bitmap[0])] |=
\r
122 - 1 << (doc_id % sizeof (bitmap[0]));
\r
123 + unsigned int doc_id = g_array_index (arr, unsigned int, i);
\r
124 + bitmap[BITMAP_WORD(doc_id)] |= 1 << BITMAP_BIT(doc_id);
\r
128 @@ -282,19 +287,17 @@ notmuch_bool_t
\r
129 _notmuch_doc_id_set_contains (notmuch_doc_id_set_t *doc_ids,
\r
130 unsigned int doc_id)
\r
132 - if (doc_id >= doc_ids->bound)
\r
133 + if (doc_id > doc_ids->max)
\r
135 - return (doc_ids->bitmap[doc_id / sizeof (doc_ids->bitmap[0])] &
\r
136 - (1 << (doc_id % sizeof (doc_ids->bitmap[0])))) != 0;
\r
137 + return doc_ids->bitmap[BITMAP_WORD(doc_id)] & (1 << BITMAP_BIT(doc_id));
\r
141 _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,
\r
142 unsigned int doc_id)
\r
144 - if (doc_id < doc_ids->bound)
\r
145 - doc_ids->bitmap[doc_id / sizeof (doc_ids->bitmap[0])] &=
\r
146 - ~(1 << (doc_id % sizeof (doc_ids->bitmap[0])));
\r
147 + if (doc_id <= doc_ids->max)
\r
148 + doc_ids->bitmap[BITMAP_WORD(doc_id)] &= ~(1 << BITMAP_BIT(doc_id));
\r
151 /* Glib objects force use to use a talloc destructor as well, (but not
\r
152 @@ -315,7 +318,6 @@ notmuch_query_search_threads (notmuch_query_t *query)
\r
154 notmuch_threads_t *threads;
\r
155 notmuch_messages_t *messages;
\r
156 - Xapian::docid max_doc_id = 0;
\r
158 threads = talloc (query, notmuch_threads_t);
\r
159 if (threads == NULL)
\r
160 @@ -335,7 +337,6 @@ notmuch_query_search_threads (notmuch_query_t *query)
\r
161 while (notmuch_messages_valid (messages)) {
\r
162 unsigned int doc_id = _notmuch_mset_messages_get_doc_id (messages);
\r
163 g_array_append_val (threads->doc_ids, doc_id);
\r
164 - max_doc_id = MAX (max_doc_id, doc_id);
\r
165 notmuch_messages_move_to_next (messages);
\r
167 threads->doc_id_pos = 0;
\r
168 @@ -343,7 +344,7 @@ notmuch_query_search_threads (notmuch_query_t *query)
\r
169 talloc_free (messages);
\r
171 if (! _notmuch_doc_id_set_init (threads, &threads->match_set,
\r
172 - threads->doc_ids, max_doc_id + 1)) {
\r
173 + threads->doc_ids)) {
\r
174 talloc_free (threads);
\r