Make value_byte a helper

This commit is contained in:
apio 2022-12-05 12:53:16 +01:00
parent 004e13a5f3
commit 86a12f301e
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 7 additions and 5 deletions

View File

@ -38,6 +38,11 @@ class Bitmap
void clear_region(usize start, usize bits, bool value);
private:
u8 value_byte(bool b)
{
return b ? 0xff : 0;
}
char* m_location = nullptr;
usize m_size_in_bytes = 0;
};

View File

@ -54,8 +54,7 @@ bool Bitmap::get(usize index) const
void Bitmap::clear(bool value)
{
expect(initialized(), "Bitmap was never initialized");
u8 value_byte = value ? 0xff : 0;
memset(m_location, value_byte, m_size_in_bytes);
memset(m_location, value_byte(value), m_size_in_bytes);
}
void Bitmap::clear_region(usize start, usize bits, bool value)
@ -63,8 +62,6 @@ void Bitmap::clear_region(usize start, usize bits, bool value)
expect(initialized(), "Bitmap was never initialized");
expect((start + bits) <= size(), "Bitmap clear out of range");
u8 value_byte = value ? 0xff : 0;
// Set individual bits while not on a byte boundary.
while ((start % 8) && bits--)
{
@ -75,7 +72,7 @@ void Bitmap::clear_region(usize start, usize bits, bool value)
// Clear out the rest in bytes.
usize bytes = bits / 8;
memset(&m_location[start / 8], value_byte, bytes);
memset(&m_location[start / 8], value_byte(value), bytes);
start += bytes * 8;
bits -= bytes * 8;