Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5FB9B429E20 for ; Sun, 30 Jan 2011 20:24:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tBqwnMLnEQPl for ; Sun, 30 Jan 2011 20:24:35 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 664D4431FB5 for ; Sun, 30 Jan 2011 20:24:35 -0800 (PST) X-AuditID: 1209190f-b7c1dae000000a2b-fc-4d4639838196 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with SMTP id 04.BD.02603.389364D4; Sun, 30 Jan 2011 23:24:35 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id p0V4OYTv015107; Sun, 30 Jan 2011 23:24:34 -0500 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0V4OW4R007254 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 30 Jan 2011 23:24:33 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.72) (envelope-from ) id 1PjlJY-00043v-Nr; Sun, 30 Jan 2011 23:24:32 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/2] Remove code repetition in the doc ID bitmap code. Date: Sun, 30 Jan 2011 23:22:32 -0500 Message-Id: <1296447753-10109-2-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <8762t8n22a.fsf@yoom.home.cworth.org> References: <8762t8n22a.fsf@yoom.home.cworth.org> X-Brightmail-Tracker: AAAAAA== Cc: amdragon@mit.edu X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2011 04:24:36 -0000 Remove the repeated "sizeof (doc_ids->bitmap[0])" that bothered cworth by instead defining macros to compute the word and bit offset of a given bit in the doc ID set bitmap. --- lib/query.cc | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index c7ae4ee..c155470 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -41,6 +41,9 @@ struct _notmuch_doc_id_set { unsigned int bound; }; +#define DOCIDSET_WORD(bit) ((bit) / sizeof (unsigned int)) +#define DOCIDSET_BIT(bit) ((bit) % sizeof (unsigned int)) + struct _notmuch_threads { notmuch_query_t *query; @@ -270,9 +273,8 @@ _notmuch_doc_id_set_init (void *ctx, doc_ids->bound = bound; for (unsigned int i = 0; i < arr->len; i++) { - unsigned int doc_id = g_array_index(arr, unsigned int, i); - bitmap[doc_id / sizeof (bitmap[0])] |= - 1 << (doc_id % sizeof (bitmap[0])); + unsigned int doc_id = g_array_index (arr, unsigned int, i); + bitmap[DOCIDSET_WORD(doc_id)] |= 1 << DOCIDSET_BIT(doc_id); } return TRUE; @@ -284,8 +286,7 @@ _notmuch_doc_id_set_contains (notmuch_doc_id_set_t *doc_ids, { if (doc_id >= doc_ids->bound) return FALSE; - return (doc_ids->bitmap[doc_id / sizeof (doc_ids->bitmap[0])] & - (1 << (doc_id % sizeof (doc_ids->bitmap[0])))) != 0; + return doc_ids->bitmap[DOCIDSET_WORD(doc_id)] & (1 << DOCIDSET_BIT(doc_id)); } void @@ -293,8 +294,7 @@ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids, unsigned int doc_id) { if (doc_id < doc_ids->bound) - doc_ids->bitmap[doc_id / sizeof (doc_ids->bitmap[0])] &= - ~(1 << (doc_id % sizeof (doc_ids->bitmap[0]))); + doc_ids->bitmap[DOCIDSET_WORD(doc_id)] &= ~(1 << DOCIDSET_BIT(doc_id)); } /* Glib objects force use to use a talloc destructor as well, (but not -- 1.7.2.3