]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blobdiff - bitvect.h
Properly prepare the scalars before filling or copying into them
[perl/modules/Scalar-Vec-Util.git] / bitvect.h
index a90ada96b4a1c5acae52b3f13d9d57519da9c0ca..0f096fdb7f61ec000de50f0cd8d6705485f5f116 100644 (file)
--- a/bitvect.h
+++ b/bitvect.h
 # define BV_UNIT unsigned char
 #endif
 
-#define BV_SIZE(I) ((((I) % CHAR_BIT) != 0) + ((I) / CHAR_BIT))
-
 #define BITS(T) (CHAR_BIT * sizeof(T))
 
+#define BV_SIZE(I) (((((I) % BITS(BV_UNIT)) != 0) + ((I) / BITS(BV_UNIT))) * sizeof(BV_UNIT))
+
 /* 0 <= I <  CHAR_BIT * sizeof(T) */
 #define BV_MASK_LOWER(T, I)  (~((~((T) 0)) << (I)))
 /* 0 <  I <= CHAR_BIT * sizeof(T) */
@@ -230,9 +230,6 @@ INLINE_DECLARE(void bv_copy(void *t_, size_t ts, const void *f_, size_t fs, size
  T ins, mask, *t = (T *) t_;
  const T *f = (const T *) f_, *end;
 
- if (!l)
-  return;
-
  t  += ts / BITS(T);
  ts %= BITS(T);
 
@@ -295,7 +292,7 @@ INLINE_DECLARE(void bv_move(void *bv_, size_t ts, size_t fs, size_t l))
  T ins, tmp, mask, *bv = (T *) bv_, *t, *f;
  const T *begin, *end;
 
- if (!l || ts == fs)
+ if (ts == fs)
   return;
 
  to = ts % BITS(T);
@@ -503,11 +500,8 @@ INLINE_DECLARE(void bv_fill(void *bv_, size_t s, size_t l, unsigned int f))
  size_t o, k;
  T mask, *bv = (T *) bv_;
 
- if (!l)
-  return;
-
  if (f)
-  f = ~0;
+  f = ~0u;
 
  bv += s / BITS(T);
  o   = s % BITS(T);