[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.
Robert Mast
beheerder at tekenbeetziekten.nl
Sun Feb 3 10:51:31 PST 2013
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
More information about the notmuch
mailing list