--- /dev/null
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 798AD431FB5\r
+ for <notmuch@notmuchmail.org>; Sun, 30 Jan 2011 20:24:36 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id UHkH5suiNxas for <notmuch@notmuchmail.org>;\r
+ Sun, 30 Jan 2011 20:24:35 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+ [18.9.25.15])\r
+ by olra.theworths.org (Postfix) with ESMTP id 9A005431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 30 Jan 2011 20:24:35 -0800 (PST)\r
+X-AuditID: 1209190f-b7c1dae000000a2b-fe-4d4639831bdf\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with\r
+ SMTP id 24.BD.02603.389364D4; Sun, 30 Jan 2011 23:24:35 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p0V4OZKK015393; \r
+ Sun, 30 Jan 2011 23:24:35 -0500\r
+Received: from drake.mit.edu\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0V4OYC8007256\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sun, 30 Jan 2011 23:24:34 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
+ (envelope-from <amthrax@drake.mit.edu>)\r
+ id 1PjlJa-000445-11; Sun, 30 Jan 2011 23:24:34 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] Simplify _notmuch_doc_id_set_init interface.\r
+Date: Sun, 30 Jan 2011 23:22:33 -0500\r
+Message-Id: <1296447753-10109-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <8762t8n22a.fsf@yoom.home.cworth.org>\r
+References: <8762t8n22a.fsf@yoom.home.cworth.org>\r
+X-Brightmail-Tracker: AAAAAA==\r
+Cc: amdragon@mit.edu\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 31 Jan 2011 04:24:36 -0000\r
+\r
+Don't require the caller of _notmuch_doc_id_set_init to pass in a\r
+correct bound; instead compute it from the array. This simplifies the\r
+caller and makes this interface easier to use correctly.\r
+---\r
+ lib/query.cc | 17 +++++++++--------\r
+ 1 files changed, 9 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index c155470..07e695b 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -260,17 +260,20 @@ _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages)\r
+ static notmuch_bool_t\r
+ _notmuch_doc_id_set_init (void *ctx,\r
+ notmuch_doc_id_set_t *doc_ids,\r
+- GArray *arr, unsigned int bound)\r
++ GArray *arr)\r
+ {\r
+- size_t count = (bound + sizeof (doc_ids->bitmap[0]) - 1) /\r
+- sizeof (doc_ids->bitmap[0]);\r
+- unsigned int *bitmap = talloc_zero_array (ctx, unsigned int, count);\r
++ unsigned int max = 0;\r
++ unsigned int *bitmap;\r
++\r
++ for (unsigned int i = 0; i < arr->len; i++)\r
++ max = MAX(max, g_array_index (arr, unsigned int, i));\r
++ bitmap = talloc_zero_array (ctx, unsigned int, 1 + max / sizeof (*bitmap));\r
+ \r
+ if (bitmap == NULL)\r
+ return FALSE;\r
+ \r
+ doc_ids->bitmap = bitmap;\r
+- doc_ids->bound = bound;\r
++ doc_ids->bound = max + 1;\r
+ \r
+ for (unsigned int i = 0; i < arr->len; i++) {\r
+ unsigned int doc_id = g_array_index (arr, unsigned int, i);\r
+@@ -315,7 +318,6 @@ notmuch_query_search_threads (notmuch_query_t *query)\r
+ {\r
+ notmuch_threads_t *threads;\r
+ notmuch_messages_t *messages;\r
+- Xapian::docid max_doc_id = 0;\r
+ \r
+ threads = talloc (query, notmuch_threads_t);\r
+ if (threads == NULL)\r
+@@ -335,7 +337,6 @@ notmuch_query_search_threads (notmuch_query_t *query)\r
+ while (notmuch_messages_valid (messages)) {\r
+ unsigned int doc_id = _notmuch_mset_messages_get_doc_id (messages);\r
+ g_array_append_val (threads->doc_ids, doc_id);\r
+- max_doc_id = MAX (max_doc_id, doc_id);\r
+ notmuch_messages_move_to_next (messages);\r
+ }\r
+ threads->doc_id_pos = 0;\r
+@@ -343,7 +344,7 @@ notmuch_query_search_threads (notmuch_query_t *query)\r
+ talloc_free (messages);\r
+ \r
+ if (! _notmuch_doc_id_set_init (threads, &threads->match_set,\r
+- threads->doc_ids, max_doc_id + 1)) {\r
++ threads->doc_ids)) {\r
+ talloc_free (threads);\r
+ return NULL;\r
+ }\r
+-- \r
+1.7.2.3\r
+\r