diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 012dd80..434c5fd 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -116,14 +116,20 @@ struct BitSet { // Check begin partial word if (begin & 63) { uint64_t word = words[begin >> 6] & (uint64_t(-1) << (begin & 63)); - while (word) { - uint64_t temp = word & -word; - int index = (begin & ~63) + std::countr_zero(word); - f(index); - word ^= temp; + if (std::popcount(word) + (begin & 63) == 64) { + while (begin & 63) { + f(begin++); + } + } else { + while (word) { + uint64_t temp = word & -word; + int index = (begin & ~63) + std::countr_zero(word); + f(index); + word ^= temp; + } + begin &= ~63; + begin += 64; } - begin &= ~63; - begin += 64; } // Check inner, full words @@ -147,11 +153,17 @@ struct BitSet { if (end & 63) { // Check end partial word uint64_t word = words[end >> 6] & ~(uint64_t(-1) << (end & 63)); - while (word) { - uint64_t temp = word & -word; - int index = begin + std::countr_zero(word); - f(index); - word ^= temp; + if (std::popcount(word) == (end & 63)) { + while (begin < end) { + f(begin++); + } + } else { + while (word) { + uint64_t temp = word & -word; + int index = begin + std::countr_zero(word); + f(index); + word ^= temp; + } } } }