[PATCH 1/2] Remove code repetition in the doc ID bitmap code.
authorAustin Clements <amdragon@MIT.EDU>
Mon, 31 Jan 2011 04:22:32 +0000 (23:22 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:50 +0000 (09:37 -0800)
5b/0b97ac86aeed2e421c3dd0efbdec6f37c50627 [new file with mode: 0644]

diff --git a/5b/0b97ac86aeed2e421c3dd0efbdec6f37c50627 b/5b/0b97ac86aeed2e421c3dd0efbdec6f37c50627
new file mode 100644 (file)
index 0000000..e68cc01
--- /dev/null
@@ -0,0 +1,117 @@
+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 5FB9B429E20\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 tBqwnMLnEQPl 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 664D4431FB5\r
+       for <notmuch@notmuchmail.org>; Sun, 30 Jan 2011 20:24:35 -0800 (PST)\r
+X-AuditID: 1209190f-b7c1dae000000a2b-fc-4d4639838196\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with\r
+       SMTP id 04.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-4.mit.edu (8.13.8/8.9.2) with ESMTP id p0V4OYTv015107; \r
+       Sun, 30 Jan 2011 23:24:34 -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 p0V4OW4R007254\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 30 Jan 2011 23:24:33 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1PjlJY-00043v-Nr; Sun, 30 Jan 2011 23:24:32 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] Remove code repetition in the doc ID bitmap code.\r
+Date: Sun, 30 Jan 2011 23:22:32 -0500\r
+Message-Id: <1296447753-10109-2-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
+Remove the repeated "sizeof (doc_ids->bitmap[0])" that bothered cworth\r
+by instead defining macros to compute the word and bit offset of a\r
+given bit in the doc ID set bitmap.\r
+---\r
+ lib/query.cc |   14 +++++++-------\r
+ 1 files changed, 7 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index c7ae4ee..c155470 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -41,6 +41,9 @@ struct _notmuch_doc_id_set {\r
+     unsigned int bound;\r
+ };\r
\r
++#define DOCIDSET_WORD(bit) ((bit) / sizeof (unsigned int))\r
++#define DOCIDSET_BIT(bit) ((bit) % sizeof (unsigned int))\r
++\r
+ struct _notmuch_threads {\r
+     notmuch_query_t *query;\r
\r
+@@ -270,9 +273,8 @@ _notmuch_doc_id_set_init (void *ctx,\r
+     doc_ids->bound = bound;\r
\r
+     for (unsigned int i = 0; i < arr->len; i++) {\r
+-      unsigned int doc_id = g_array_index(arr, unsigned int, i);\r
+-      bitmap[doc_id / sizeof (bitmap[0])] |=\r
+-          1 << (doc_id % sizeof (bitmap[0]));\r
++      unsigned int doc_id = g_array_index (arr, unsigned int, i);\r
++      bitmap[DOCIDSET_WORD(doc_id)] |= 1 << DOCIDSET_BIT(doc_id);\r
+     }\r
\r
+     return TRUE;\r
+@@ -284,8 +286,7 @@ _notmuch_doc_id_set_contains (notmuch_doc_id_set_t *doc_ids,\r
+ {\r
+     if (doc_id >= doc_ids->bound)\r
+       return FALSE;\r
+-    return (doc_ids->bitmap[doc_id / sizeof (doc_ids->bitmap[0])] &\r
+-          (1 << (doc_id % sizeof (doc_ids->bitmap[0])))) != 0;\r
++    return doc_ids->bitmap[DOCIDSET_WORD(doc_id)] & (1 << DOCIDSET_BIT(doc_id));\r
+ }\r
\r
+ void\r
+@@ -293,8 +294,7 @@ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,\r
+                             unsigned int doc_id)\r
+ {\r
+     if (doc_id < doc_ids->bound)\r
+-      doc_ids->bitmap[doc_id / sizeof (doc_ids->bitmap[0])] &=\r
+-          ~(1 << (doc_id % sizeof (doc_ids->bitmap[0])));\r
++      doc_ids->bitmap[DOCIDSET_WORD(doc_id)] &= ~(1 << DOCIDSET_BIT(doc_id));\r
+ }\r
\r
+ /* Glib objects force use to use a talloc destructor as well, (but not\r
+-- \r
+1.7.2.3\r
+\r