diff --git a/luna/include/luna/Bitmap.h b/luna/include/luna/Bitmap.h index 463c88e5..b7464e14 100644 --- a/luna/include/luna/Bitmap.h +++ b/luna/include/luna/Bitmap.h @@ -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; }; \ No newline at end of file diff --git a/luna/src/Bitmap.cpp b/luna/src/Bitmap.cpp index f7b91156..05566e3b 100644 --- a/luna/src/Bitmap.cpp +++ b/luna/src/Bitmap.cpp @@ -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;