From: Robert Mast Date: Sun, 3 Feb 2013 18:51:31 +0000 (+0100) Subject: [PATCH] This patch is a little finger excercise for working with git. I found a piece... X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=ba9021bbda0a97d15399e2142418bf230ef75662;p=notmuch-archives.git [PATCH] This patch is a little finger excercise for working with git. I found a piece of code that I didn't understand at first. --- diff --git a/0e/a1b9fecc48506a4f47c6b70d46d17e8b48b8a1 b/0e/a1b9fecc48506a4f47c6b70d46d17e8b48b8a1 new file mode 100644 index 000000000..f2756d059 --- /dev/null +++ b/0e/a1b9fecc48506a4f47c6b70d46d17e8b48b8a1 @@ -0,0 +1,84 @@ +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 5C0E5431FB6 + for ; Sun, 3 Feb 2013 10:52:34 -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 mlsuUvolgfTp for ; + Sun, 3 Feb 2013 10:52:32 -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 A1F5D431FAE + for ; Sun, 3 Feb 2013 10:52:31 -0800 (PST) +Received: (qmail 25815 invoked from network); 3 Feb 2013 19:52:28 +0100 +Received: from ip73-109-210-87.adsl2.static.versatel.nl (HELO linux2.foo) + (87.210.109.73) + by srv047132.webreus.nl with SMTP; 3 Feb 2013 19:52:27 +0100 +From: Robert Mast +To: notmuch@notmuchmail.org +Subject: [PATCH] This patch is a little finger excercise for working with git. + I found a piece of code that I didn't understand at first. +Date: Sun, 3 Feb 2013 19:51:31 +0100 +Message-Id: <1359917491-17178-1-git-send-email-beheerder@tekenbeetziekten.nl> +X-Mailer: git-send-email 1.7.9.5 +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: Sun, 03 Feb 2013 18:52:34 -0000 + +Reading it in detail I thought it allocated way too much memory and +didn't use the full size of the allocated unsigned ints for storing +bits. + +Am I right, and is this the right way to patch code to notmuch? + +--- + lib/query.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/lib/query.cc b/lib/query.cc +index e9c1a2d..046663a 100644 +--- a/lib/query.cc ++++ b/lib/query.cc +@@ -43,8 +43,8 @@ struct _notmuch_doc_id_set { + unsigned int bound; + }; + +-#define DOCIDSET_WORD(bit) ((bit) / sizeof (unsigned int)) +-#define DOCIDSET_BIT(bit) ((bit) % sizeof (unsigned int)) ++#define DOCIDSET_WORD(bit) ((bit) / (sizeof (unsigned int) * CHAR_BIT)) ++#define DOCIDSET_BIT(bit) ((bit) % (sizeof (unsigned int) * CHAR_BIT)) + + struct visible _notmuch_threads { + notmuch_query_t *query; +@@ -363,7 +363,7 @@ _notmuch_doc_id_set_init (void *ctx, + + 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 int, (DOCIDSET_WORD(max) + 1) * sizeof (*bitmap)); + + if (bitmap == NULL) + return FALSE; +-- +1.7.9.5 +