unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [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.
@ 2013-02-03 18:51 Robert Mast
  2013-02-03 20:01 ` Austin Clements
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Robert Mast @ 2013-02-03 18:51 UTC (permalink / raw)
  To: notmuch; +Cc: Robert Mast

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-02-16 11:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-03 18:51 [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
2013-02-03 20:01 ` Austin Clements
2013-02-10 13:13 ` [PATCH] convert bitmap to unsigned char Robert Mast
2013-02-11 18:56   ` Carl Worth
2013-02-10 17:24 ` [PATCH] bitmap:improve memory usage using CHAR_BITS and unsigned CHAR Robert Mast
2013-02-13 15:11 ` Robert Mast
2013-02-13 15:15   ` [english 100%] " Robert Mast
2013-02-13 15:32 ` Robert Mast
2013-02-13 16:21   ` Carl Worth
2013-02-16 11:37   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).