readability tweaks

This commit is contained in:
Rémy Rakic 2023-03-27 16:02:53 +00:00
parent a69642015a
commit a2be7a1bb4

View File

@ -254,44 +254,44 @@ impl InitMaskMaterialized {
} }
fn set_range_inbounds(&mut self, start: Size, end: Size, new_state: bool) { fn set_range_inbounds(&mut self, start: Size, end: Size, new_state: bool) {
let (blocka, bita) = Self::bit_index(start); let (block_a, bit_a) = Self::bit_index(start);
let (blockb, bitb) = Self::bit_index(end); let (block_b, bit_b) = Self::bit_index(end);
if blocka == blockb { if block_a == block_b {
// First set all bits except the first `bita`, // First set all bits except the first `bit_a`,
// then unset the last `64 - bitb` bits. // then unset the last `64 - bit_b` bits.
let range = if bitb == 0 { let range = if bit_b == 0 {
u64::MAX << bita u64::MAX << bit_a
} else { } else {
(u64::MAX << bita) & (u64::MAX >> (64 - bitb)) (u64::MAX << bit_a) & (u64::MAX >> (64 - bit_b))
}; };
if new_state { if new_state {
self.blocks[blocka] |= range; self.blocks[block_a] |= range;
} else { } else {
self.blocks[blocka] &= !range; self.blocks[block_a] &= !range;
} }
return; return;
} }
// across block boundaries // across block boundaries
if new_state { if new_state {
// Set `bita..64` to `1`. // Set `bit_a..64` to `1`.
self.blocks[blocka] |= u64::MAX << bita; self.blocks[block_a] |= u64::MAX << bit_a;
// Set `0..bitb` to `1`. // Set `0..bit_b` to `1`.
if bitb != 0 { if bit_b != 0 {
self.blocks[blockb] |= u64::MAX >> (64 - bitb); self.blocks[block_b] |= u64::MAX >> (64 - bit_b);
} }
// Fill in all the other blocks (much faster than one bit at a time). // Fill in all the other blocks (much faster than one bit at a time).
for block in (blocka + 1)..blockb { for block in (block_a + 1)..block_b {
self.blocks[block] = u64::MAX; self.blocks[block] = u64::MAX;
} }
} else { } else {
// Set `bita..64` to `0`. // Set `bit_a..64` to `0`.
self.blocks[blocka] &= !(u64::MAX << bita); self.blocks[block_a] &= !(u64::MAX << bit_a);
// Set `0..bitb` to `0`. // Set `0..bit_b` to `0`.
if bitb != 0 { if bit_b != 0 {
self.blocks[blockb] &= !(u64::MAX >> (64 - bitb)); self.blocks[block_b] &= !(u64::MAX >> (64 - bit_b));
} }
// Fill in all the other blocks (much faster than one bit at a time). // Fill in all the other blocks (much faster than one bit at a time).
for block in (blocka + 1)..blockb { for block in (block_a + 1)..block_b {
self.blocks[block] = 0; self.blocks[block] = 0;
} }
} }