bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/7] bitset: use integrer_length in list implementation


From: Akim Demaille
Subject: [PATCH 6/7] bitset: use integrer_length in list implementation
Date: Sun, 29 Nov 2020 17:42:20 +0100

* lib/bitset/list.c (lbitset_list_reverse): Use
BITSET_FOR_EACH_BIT_REVERSE.
---
 ChangeLog         |  6 ++++++
 lib/bitset/list.c | 26 ++++++++++++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 37024c15c..c0013145d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: use integrer_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 integrer_length in vector implementation
diff --git a/lib/bitset/list.c b/lib/bitset/list.c
index e931fe1ca..9a5d48282 100644
--- a/lib/bitset/list.c
+++ b/lib/bitset/list.c
@@ -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;
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]