]> Savannah Git Hosting - gnulib.git/commitdiff
bitset: use integer_length in vector implementation
authorAkim Demaille <akim.demaille@gmail.com>
Sun, 29 Nov 2020 14:55:35 +0000 (15:55 +0100)
committerAkim Demaille <akim.demaille@gmail.com>
Mon, 30 Nov 2020 05:53:55 +0000 (06:53 +0100)
* lib/bitset/array.c (vbitset_list_reverse): Use
BITSET_FOR_EACH_BIT_REVERSE.

ChangeLog
lib/bitset/vector.c

index c3c5574f8e9c1510450f6edeecff21fc51432712..b03ea1cd7771955b93e25f8936db6db3c84b64da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: use integer_length in vector implementation
+       * lib/bitset/array.c (vbitset_list_reverse): Use
+       BITSET_FOR_EACH_BIT_REVERSE.
+
 2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
 
        bitset: use integer_length in array implementation
index 4c0c9dbfd21836c6223513c1f7cdc5d02df1effb..9f1c08e7745edac7d243a17110278c93aa8d2585 100644 (file)
@@ -152,11 +152,11 @@ static bitset_bindex
 vbitset_list_reverse (bitset src, bitset_bindex *list,
                       bitset_bindex num, bitset_bindex *next)
 {
+  /* FIXME: almost a duplicate of abitset_list_reverse.  Factor?  */
+  bitset_bindex rbitno = *next;
   bitset_word *srcp = VBITSET_WORDS (src);
   bitset_bindex n_bits = BITSET_SIZE_ (src);
 
-  bitset_bindex rbitno = *next;
-
   /* If num is 1, we could speed things up with a binary search
      of the word of interest.  */
 
@@ -173,19 +173,18 @@ vbitset_list_reverse (bitset src, bitset_bindex *list,
 
   do
     {
-      bitset_word word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt);
-      for (; word; bitcnt--)
+      bitset_word word = srcp[windex];
+      if (bitcnt + 1 < BITSET_WORD_BITS)
+        /* We're starting in the middle of a word: smash bits to ignore.  */
+        word &= ((bitset_word) 1 << (bitcnt + 1)) - 1;
+      BITSET_FOR_EACH_BIT_REVERSE(pos, word)
         {
-          if (word & BITSET_MSB)
+          list[count++] = bitoff + pos;
+          if (count >= num)
             {
-              list[count++] = bitoff + bitcnt;
-              if (count >= num)
-                {
-                  *next = n_bits - (bitoff + bitcnt);
-                  return count;
-                }
+              *next = n_bits - (bitoff + pos);
+              return count;
             }
-          word <<= 1;
         }
       bitoff -= BITSET_WORD_BITS;
       bitcnt = BITSET_WORD_BITS - 1;