From b141afaf9ba197e361510da075556822ac453ff6 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 29 Nov 2020 17:09:47 +0100 Subject: [PATCH] bitset: use integer_length in table implementation * lib/bitset/table.c (tbitset_list_reverse): Use BITSET_FOR_EACH_BIT_REVERSE. --- ChangeLog | 6 ++++++ lib/bitset/table.c | 19 +++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8fc0e65d46..f350418137 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-11-29 Akim Demaille + + 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 bitset: use integer_length in list implementation diff --git a/lib/bitset/table.c b/lib/bitset/table.c index 48c88e02ba..16781958a7 100644 --- a/lib/bitset/table.c +++ b/lib/bitset/table.c @@ -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; -- 2.39.5