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

ChangeLog
lib/bitset/list.c

index b03ea1cd7771955b93e25f8936db6db3c84b64da..8fc0e65d468dfa4acd89bf505ae47ae341519bdb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: use integer_length in list implementation
+       * lib/bitset/list.c (lbitset_list_reverse): Use
+       BITSET_FOR_EACH_BIT_REVERSE.
+
 2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
 
        bitset: use integer_length in vector implementation
index e931fe1cae88befbef6e1a6deb4d1897f1b1c257..9a5d4828233752332eb456491e938871c7bff5a0 100644 (file)
@@ -604,25 +604,23 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list,
       bitset_word *srcp = elt->words;
 
       for (; (windex - elt->index) < LBITSET_ELT_WORDS;
-           windex--, bitoff -= BITSET_WORD_BITS,
-             bitcnt = BITSET_WORD_BITS - 1)
+           windex--)
         {
-          bitset_word word =
-            srcp[windex - elt->index] << (BITSET_WORD_BITS - 1 - bitcnt);
-
-          for (; word; bitcnt--)
+          bitset_word word = srcp[windex - elt->index];
+          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;
         }
 
       elt = elt->prev;