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

ChangeLog
lib/bitset/table.c

index 8fc0e65d468dfa4acd89bf505ae47ae341519bdb..f350418137afe19f144debddaf289029b9e79dd2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: use integer_length in table implementation
+       * lib/bitset/table.c (tbitset_list_reverse): Use
+       BITSET_FOR_EACH_BIT_REVERSE.
+
 2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
 
        bitset: use integer_length in list implementation
index 48c88e02ba589102cb4a51d91188773c25e9a491..16781958a7c1fb637aa08cc365995ee9e690e63c 100644 (file)
@@ -562,19 +562,18 @@ tbitset_list_reverse (bitset bset, bitset_bindex *list,
 
           do
             {
-              for (bitset_word word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bitcnt);
-                   word; bitcnt--)
+              bitset_word word = srcp[woffset];
+              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;