From 08997007f2c9ecb73dd2cba73c748e93f8c49238 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 18 Jun 2023 19:28:22 +0200 Subject: [PATCH] libluna: Stop checking initialization status on every bitmap method call 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. --- libluna/src/Bitmap.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libluna/src/Bitmap.cpp b/libluna/src/Bitmap.cpp index 2cdc8037..b32285cc 100644 --- a/libluna/src/Bitmap.cpp +++ b/libluna/src/Bitmap.cpp @@ -37,8 +37,6 @@ Result 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 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 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);