libluna: Stop checking initialization status on every bitmap method call
All checks were successful
continuous-integration/drone/push Build is passing

Since our asserts (expect()) are enabled on release as well, this is kinda expensive.

It's up to the caller, if they receive a null pointer dereference it's
their fault for not initializing their bitmap :)

We do still assert out-of-range indexing and stuff like that.
This commit is contained in:
apio 2023-06-18 19:28:22 +02:00
parent 148c1c7341
commit 08997007f2
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -37,8 +37,6 @@ Result<void> Bitmap::deallocate()
void* Bitmap::move(void* new_location, usize new_location_size_in_bytes)
{
expect(initialized(), "Bitmap was never initialized");
if (new_location_size_in_bytes > m_size_in_bytes) memcpy(new_location, m_location, m_size_in_bytes);
else
memcpy(new_location, m_location, new_location_size_in_bytes);
@ -53,7 +51,6 @@ void* Bitmap::move(void* new_location, usize new_location_size_in_bytes)
void Bitmap::set(usize index, bool value)
{
expect(initialized(), "Bitmap was never initialized");
expect(index < size(), "Bitmap access out of range");
const u64 byte_index = index / 8;
const u8 bit_mask = (u8)(0b10000000 >> (index % 8));
@ -63,7 +60,6 @@ void Bitmap::set(usize index, bool value)
bool Bitmap::get(usize index) const
{
expect(initialized(), "Bitmap was never initialized");
expect(index < size(), "Bitmap access out of range");
const usize byte_index = index / 8;
const u8 bit_mask = (u8)(0b10000000 >> (index % 8));
@ -72,13 +68,11 @@ bool Bitmap::get(usize index) const
void Bitmap::clear(bool value)
{
expect(initialized(), "Bitmap was never initialized");
memset(m_location, value_byte(value), m_size_in_bytes);
}
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");
if (!bits) return;
@ -108,8 +102,6 @@ void Bitmap::clear_region(usize start, usize bits, bool value)
Option<usize> Bitmap::find(bool value, usize begin) const
{
expect(initialized(), "Bitmap was never initialized");
const usize size = this->size();
expect(begin < size, "Start index out of range");
@ -223,7 +215,6 @@ bool Bitmap::match_region_impl(usize start, usize bits, bool value)
bool Bitmap::match_region(usize start, usize bits, bool value)
{
expect(initialized(), "Bitmap was never initialized");
expect((start + bits) <= size(), "Bitmap match out of range");
return match_region_impl(start, bits, value);
@ -231,7 +222,6 @@ bool Bitmap::match_region(usize start, usize bits, bool value)
Result<bool> Bitmap::try_match_region(usize start, usize bits, bool value)
{
expect(initialized(), "Bitmap was never initialized");
if ((start + bits) > size()) return err(EINVAL);
return match_region_impl(start, bits, value);