diff options
Diffstat (limited to 'src/common/slot_vector.h')
| -rw-r--r-- | src/common/slot_vector.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/common/slot_vector.h b/src/common/slot_vector.h index f6da7a59d1..8e1c06e35a 100644 --- a/src/common/slot_vector.h +++ b/src/common/slot_vector.h @@ -52,12 +52,16 @@ public: const u64* const bitset = slot_vector->stored_bitset.data(); const u32 size = static_cast<u32>(slot_vector->stored_bitset.size()) * 64; if (id.Value() < size) { - do { - ++id.index; - } while (id.Value() < size && !IsValid(bitset)); - if (id.Value() == size) { - id = SlotId{}; + u32 index = id.Value() + 1; + while (index < size) { + const u64 word = bitset[index / 64] >> (index % 64); + if (word != 0) { + index += static_cast<u32>(std::countr_zero(word)); + break; + } + index = (index / 64 + 1) * 64; } + id = index < size ? SlotId{index} : SlotId{}; } return *this; } @@ -139,7 +143,7 @@ public: if (it == stored_bitset.end()) { return end(); } - const u32 word_index = static_cast<u32>(std::distance(it, stored_bitset.begin())); + const u32 word_index = static_cast<u32>(std::distance(stored_bitset.begin(), it)); const SlotId first_id{word_index * 64 + static_cast<u32>(std::countr_zero(*it))}; return Iterator(this, first_id); } |
