From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 26878431FC9 for ; Wed, 13 Feb 2013 07:33:33 -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 BDQPRYiFdQSQ for ; Wed, 13 Feb 2013 07:33:29 -0800 (PST) Received: from srv047132.webreus.nl (srv047132.webreus.nl [46.235.47.132]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D1B5A431FC7 for ; Wed, 13 Feb 2013 07:33:28 -0800 (PST) Received: (qmail 20161 invoked from network); 13 Feb 2013 16:33:27 +0100 Received: from ip73-109-210-87.adsl2.static.versatel.nl (HELO linux2.foo) (87.210.109.73) by srv047132.webreus.nl with SMTP; 13 Feb 2013 16:33:27 +0100 From: Robert Mast To: notmuch@notmuchmail.org Subject: [PATCH] bitmap:improve memory usage using CHAR_BITS and unsigned CHAR Date: Wed, 13 Feb 2013 16:32:57 +0100 Message-Id: <1360769577-4861-1-git-send-email-beheerder@tekenbeetziekten.nl> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359917491-17178-1-git-send-email-beheerder@tekenbeetziekten.nl> References: <1359917491-17178-1-git-send-email-beheerder@tekenbeetziekten.nl> Cc: Robert Mast 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: Wed, 13 Feb 2013 15:33:33 -0000 Using char instead of int allows for simpler definitions of the DOCIDSET macros so the code is easier to understand and consistent with respect to memory-usage. Estimated reduction of memory-usage for bitmap about 8 times. --- Re-submission for comment-reasons. --- --- lib/query.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index e9c1a2d..7381a54 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -39,12 +39,12 @@ typedef struct _notmuch_mset_messages { } notmuch_mset_messages_t; struct _notmuch_doc_id_set { - unsigned int *bitmap; + unsigned char *bitmap; unsigned int bound; }; -#define DOCIDSET_WORD(bit) ((bit) / sizeof (unsigned int)) -#define DOCIDSET_BIT(bit) ((bit) % sizeof (unsigned int)) +#define DOCIDSET_WORD(bit) ((bit) / CHAR_BIT) +#define DOCIDSET_BIT(bit) ((bit) % CHAR_BIT) struct visible _notmuch_threads { notmuch_query_t *query; @@ -359,11 +359,11 @@ _notmuch_doc_id_set_init (void *ctx, GArray *arr) { unsigned int max = 0; - unsigned int *bitmap; + unsigned char *bitmap; for (unsigned int i = 0; i < arr->len; i++) max = MAX(max, g_array_index (arr, unsigned int, i)); - bitmap = talloc_zero_array (ctx, unsigned int, 1 + max / sizeof (*bitmap)); + bitmap = talloc_zero_array (ctx, unsigned char, DOCIDSET_WORD(max) + 1); if (bitmap == NULL) return FALSE; -- 1.7.9.5