Make value_byte a helper
This commit is contained in:
parent
004e13a5f3
commit
86a12f301e
@ -38,6 +38,11 @@ class Bitmap
|
|||||||
void clear_region(usize start, usize bits, bool value);
|
void clear_region(usize start, usize bits, bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
u8 value_byte(bool b)
|
||||||
|
{
|
||||||
|
return b ? 0xff : 0;
|
||||||
|
}
|
||||||
|
|
||||||
char* m_location = nullptr;
|
char* m_location = nullptr;
|
||||||
usize m_size_in_bytes = 0;
|
usize m_size_in_bytes = 0;
|
||||||
};
|
};
|
@ -54,8 +54,7 @@ bool Bitmap::get(usize index) const
|
|||||||
void Bitmap::clear(bool value)
|
void Bitmap::clear(bool value)
|
||||||
{
|
{
|
||||||
expect(initialized(), "Bitmap was never initialized");
|
expect(initialized(), "Bitmap was never initialized");
|
||||||
u8 value_byte = value ? 0xff : 0;
|
memset(m_location, value_byte(value), m_size_in_bytes);
|
||||||
memset(m_location, value_byte, m_size_in_bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::clear_region(usize start, usize bits, bool value)
|
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(initialized(), "Bitmap was never initialized");
|
||||||
expect((start + bits) <= size(), "Bitmap clear out of range");
|
expect((start + bits) <= size(), "Bitmap clear out of range");
|
||||||
|
|
||||||
u8 value_byte = value ? 0xff : 0;
|
|
||||||
|
|
||||||
// Set individual bits while not on a byte boundary.
|
// Set individual bits while not on a byte boundary.
|
||||||
while ((start % 8) && bits--)
|
while ((start % 8) && bits--)
|
||||||
{
|
{
|
||||||
@ -75,7 +72,7 @@ void Bitmap::clear_region(usize start, usize bits, bool value)
|
|||||||
// Clear out the rest in bytes.
|
// Clear out the rest in bytes.
|
||||||
usize bytes = bits / 8;
|
usize bytes = bits / 8;
|
||||||
|
|
||||||
memset(&m_location[start / 8], value_byte, bytes);
|
memset(&m_location[start / 8], value_byte(value), bytes);
|
||||||
start += bytes * 8;
|
start += bytes * 8;
|
||||||
bits -= bytes * 8;
|
bits -= bytes * 8;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user