Skip zero words in `bitset::count`

2320ecc36b81332accbe814e1c0953099ae7f0c7d2e446cd92adbd976e2ba6c2
Alexis Sellier committed ago 1 parent 8bde2696
lib/std/lang/gen/bitset.rad +4 -1
92 92
/// Count the number of set bits.
93 93
pub fn count(bs: *Bitset) -> u32 {
94 94
    let mut total: u32 = 0;
95 95
    let numWords = bs.bits.len;
96 96
    for i in 0..numWords {
97 -
        total += popCount(bs.bits[i]);
97 +
        let word = bs.bits[i];
98 +
        if word != 0 {
99 +
            total += popCount(word);
100 +
        }
98 101
    }
99 102
    return total;
100 103
}
101 104
102 105
/// Population count for a 32-bit word.