]> diplodocus.org Git - nmh/commitdiff
sbr/vector.c: Use new BVEC_BITS_BITS macro.
authorRalph Corderoy <ralph@inputplus.co.uk>
Fri, 28 Apr 2017 11:12:15 +0000 (12:12 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 28 Apr 2017 11:12:15 +0000 (12:12 +0100)
Factors out a common expression from a few other places.

sbr/vector.c

index 3bf4c1f083e0b95c30cb9075e795f90cf50f2937..c2bd0df913b3003e5781ab42ac33fd7aa7b69f01 100644 (file)
 
 /* 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