diff options
author | Austin Clements <amdragon@mit.edu> | 2011-01-30 20:58:27 -0500 |
---|---|---|
committer | Austin Clements <amdragon@mit.edu> | 2011-01-30 20:58:27 -0500 |
commit | e04e72f9dd9b435f37cf9e712d9e23cf22896e27 (patch) | |
tree | 061768000db0fb3d9d7d20a3347c13b99e07173b | |
parent | 15d8928f4133eb28f7823b0f4d4c5edc6471131c (diff) |
Remove code repetition in the doc ID bitmap code.
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.
-rw-r--r-- | lib/query.cc | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/query.cc b/lib/query.cc index c7ae4ee7..c155470a 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 |