Bitmap: Declare more variables as const
I miss Rust's immutability-by-default...
This commit is contained in:
parent
a6974b605e
commit
0e607c2fef
@ -24,7 +24,7 @@ void* Bitmap::move(void* new_location, usize new_location_size_in_bytes)
|
||||
else
|
||||
memcpy(new_location, m_location, new_location_size_in_bytes);
|
||||
|
||||
void* old_location = (void*)m_location;
|
||||
void* const old_location = (void*)m_location;
|
||||
|
||||
m_location = (u8*)new_location;
|
||||
m_size_in_bytes = new_location_size_in_bytes;
|
||||
@ -36,8 +36,8 @@ void Bitmap::set(usize index, bool value)
|
||||
{
|
||||
expect(initialized(), "Bitmap was never initialized");
|
||||
expect(index < size(), "Bitmap access out of range");
|
||||
u64 byte_index = index / 8;
|
||||
u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
||||
const u64 byte_index = index / 8;
|
||||
const u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
||||
m_location[byte_index] &= (u8)(~bit_mask);
|
||||
if (value) { m_location[byte_index] |= bit_mask; }
|
||||
}
|
||||
@ -46,8 +46,8 @@ bool Bitmap::get(usize index) const
|
||||
{
|
||||
expect(initialized(), "Bitmap was never initialized");
|
||||
expect(index < size(), "Bitmap access out of range");
|
||||
usize byte_index = index / 8;
|
||||
u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
||||
const usize byte_index = index / 8;
|
||||
const u8 bit_mask = (u8)(0b10000000 >> (index % 8));
|
||||
return (m_location[byte_index] & bit_mask) > 0;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ void Bitmap::clear_region(usize start, usize bits, bool value)
|
||||
}
|
||||
|
||||
// Clear out the rest in bytes.
|
||||
usize bytes = bits / 8;
|
||||
const usize bytes = bits / 8;
|
||||
|
||||
memset(&m_location[start / 8], value_byte(value), bytes);
|
||||
start += bytes * 8;
|
||||
@ -163,7 +163,7 @@ Option<usize> Bitmap::find_region(bool value, usize count, usize begin) const
|
||||
|
||||
Option<usize> Bitmap::find_and_toggle_region(bool value, usize count, usize begin)
|
||||
{
|
||||
usize index = TRY(find_region(value, count, begin));
|
||||
const usize index = TRY(find_region(value, count, begin));
|
||||
clear_region(index, count, !value);
|
||||
return index;
|
||||
}
|
||||
@ -184,7 +184,7 @@ bool Bitmap::match_region(usize start, usize bits, bool value)
|
||||
}
|
||||
|
||||
// Match the rest in bytes.
|
||||
usize bytes = bits / 8;
|
||||
const usize bytes = bits / 8;
|
||||
const u8 byte_that_contains_only_value = value_byte(value);
|
||||
|
||||
for (usize i = start; i < start + bytes; i += 8)
|
||||
|
Loading…
Reference in New Issue
Block a user