diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-11-16 07:22:35 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-11-18 06:50:28 +0100 |
commit | abc5606bb1b591cf03d51029e4d5d532d16b717e (patch) | |
tree | 50ac3f4ab7d83c24e8816acf7e0531834d779e00 /lib/bitset | |
parent | 154b4c4bb430ae91b541d0a4932cdef75710c966 (diff) | |
download | gnulib-abc5606bb1b591cf03d51029e4d5d532d16b717e.tar.gz |
bitset: use ffs where possible in array implementation
* lib/bitset/array.c (abitset_small_list): Use BITSET_FOR_EACH_BIT.
Diffstat (limited to 'lib/bitset')
-rw-r--r-- | lib/bitset/array.c | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/lib/bitset/array.c b/lib/bitset/array.c index 6c5f7ed34f..3f8bcca87d 100644 --- a/lib/bitset/array.c +++ b/lib/bitset/array.c @@ -62,38 +62,25 @@ abitset_small_list (bitset src, bitset_bindex *list, word >>= bitno; - /* If num is 1, we could speed things up with a binary search - of the word of interest. */ - - bitset_bindex count; + bitset_bindex count = 0; + /* Is there enough room to avoid checking in each iteration? */ if (num >= BITSET_WORD_BITS) { - for (count = 0; word; bitno++) - { - if (word & 1) - list[count++] = bitno; - word >>= 1; - } + BITSET_FOR_EACH_BIT (pos, word) + list[count++] = bitno + pos; + *next = bitno + BITSET_WORD_BITS; + return count; } else - { - for (count = 0; word; bitno++) - { - if (word & 1) - { - list[count++] = bitno; - if (count >= num) - { - bitno++; - break; - } - } - word >>= 1; - } - } - - *next = bitno; - return count; + BITSET_FOR_EACH_BIT (pos, word) + { + list[count++] = bitno + pos; + if (count >= num) + { + *next = bitno + pos + 1; + return count; + } + } } @@ -205,9 +192,6 @@ abitset_list (bitset src, bitset_bindex *list, if (windex >= size) return 0; - /* If num is 1, we could speed things up with a binary search - of the current word. */ - bitoff = windex * BITSET_WORD_BITS; } else |