Skip zero words in `bitset::count`

8cacf46c03fc1a9d2941ac4d8387355a7a34fe06c13eb64fd2c5e411ece108f3
Alexis Sellier committed ago 1 parent f82c0aaa
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.