diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-11-29 17:04:14 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-11-30 06:53:55 +0100 |
commit | d5db0bb5237cfcf3bf0712dc8ba1d66e230c513d (patch) | |
tree | 63c751c74de829e6bc8ce31e4fefaa5bce0fee73 /lib/bitset | |
parent | 84e08e17163c62ea0f4d2847471a9636e24d3c4d (diff) | |
download | gnulib-d5db0bb5237cfcf3bf0712dc8ba1d66e230c513d.tar.gz |
bitset: use integer_length in list implementation
* lib/bitset/list.c (lbitset_list_reverse): Use
BITSET_FOR_EACH_BIT_REVERSE.
Diffstat (limited to 'lib/bitset')
-rw-r--r-- | lib/bitset/list.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/bitset/list.c b/lib/bitset/list.c index e931fe1cae..9a5d482823 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; |