From: Ralph Corderoy Date: Fri, 28 Apr 2017 11:12:15 +0000 (+0100) Subject: sbr/vector.c: Use new BVEC_BITS_BITS macro. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/b5a92b55eb5670e982899e5dfd9aaa1d35db002f?ds=inline;hp=c8caafcb4a39516eaec330f9ea229ea52e5fe46b sbr/vector.c: Use new BVEC_BITS_BITS macro. Factors out a common expression from a few other places. --- diff --git a/sbr/vector.c b/sbr/vector.c index 3bf4c1f0..c2bd0df9 100644 --- a/sbr/vector.c +++ b/sbr/vector.c @@ -32,8 +32,10 @@ /* The *sizeof* struct bvector's bits member. Not its size in bits. */ #define BVEC_SIZEOF_BITS (sizeof *(((bvector_t)NULL)->bits)) -#define BVEC_WORD(max) ((max) / (BVEC_SIZEOF_BITS * CHAR_BIT)) -#define BVEC_OFFSET(max) ((max) % (BVEC_SIZEOF_BITS * CHAR_BIT)) +/* The number of bits held in one element of the bits member. */ +#define BVEC_BITS_BITS (BVEC_SIZEOF_BITS * CHAR_BIT) +#define BVEC_WORD(max) ((max) / BVEC_BITS_BITS) +#define BVEC_OFFSET(max) ((max) % BVEC_BITS_BITS) #define BVEC_BYTES(n) \ ((BVEC_WORD(n) + (BVEC_OFFSET(n) == 0 ? 0 : 1)) * BVEC_SIZEOF_BITS) @@ -139,8 +141,8 @@ bvector_resize (bvector_t vec, size_t maxsize) { } else vec->bits = mh_xrealloc(vec->bits, bytes); - memset(vec->bits + (old_maxsize / (BVEC_SIZEOF_BITS * CHAR_BIT)), - 0, (vec->maxsize - old_maxsize) / CHAR_BIT); + memset(vec->bits + (old_maxsize / BVEC_BITS_BITS), 0, + (vec->maxsize - old_maxsize) / CHAR_BIT); } unsigned long