diff options
author | Andreas Kling <kling@serenityos.org> | 2021-04-09 09:12:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-09 17:08:49 +0200 |
commit | c268df79e6a3918c1b040d66833e6153ebfb7513 (patch) | |
tree | d2a0d910f5d9224367e337d49c51a4ea85f532a9 /AK | |
parent | 79ebcacce291c9ec28a23464377a651765289808 (diff) | |
download | serenity-c268df79e6a3918c1b040d66833e6153ebfb7513.zip |
AK: Add BitmapView::set_range_and_verify_that_all_bits_flip()
This function sets a range of bits to the same value while also
verifying that all bits in the range get flipped in the process.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Bitmap.h | 2 | ||||
-rw-r--r-- | AK/BitmapView.h | 35 |
2 files changed, 33 insertions, 4 deletions
diff --git a/AK/Bitmap.h b/AK/Bitmap.h index 1f414e0c5e..00207b9d3e 100644 --- a/AK/Bitmap.h +++ b/AK/Bitmap.h @@ -129,7 +129,7 @@ public: } template<bool VALUE> - void set_range(size_t start, size_t len) { return view().set_range<VALUE>(start, len); } + void set_range(size_t start, size_t len) { return view().set_range<VALUE, false>(start, len); } void set_range(size_t start, size_t len, bool value) { return view().set_range(start, len, value); } void fill(bool value) { view().fill(value); } diff --git a/AK/BitmapView.h b/AK/BitmapView.h index d606f0379e..e1adfe12a5 100644 --- a/AK/BitmapView.h +++ b/AK/BitmapView.h @@ -115,7 +115,7 @@ public: u8* data() { return m_data; } const u8* data() const { return m_data; } - template<bool VALUE> + template<bool VALUE, bool verify_that_all_bits_flip> void set_range(size_t start, size_t len) { VERIFY(start < m_size); @@ -131,16 +131,37 @@ public: u8 byte_mask = bitmask_first_byte[start % 8]; if (first == last) { byte_mask &= bitmask_last_byte[(start + len) % 8]; + if constexpr (verify_that_all_bits_flip) { + if constexpr (VALUE) { + VERIFY((*first & byte_mask) == 0); + } else { + VERIFY((*first & byte_mask) == byte_mask); + } + } if constexpr (VALUE) *first |= byte_mask; else *first &= ~byte_mask; } else { + if constexpr (verify_that_all_bits_flip) { + if constexpr (VALUE) { + VERIFY((*first & byte_mask) == 0); + } else { + VERIFY((*first & byte_mask) == byte_mask); + } + } if constexpr (VALUE) *first |= byte_mask; else *first &= ~byte_mask; byte_mask = bitmask_last_byte[(start + len) % 8]; + if constexpr (verify_that_all_bits_flip) { + if constexpr (VALUE) { + VERIFY((*last & byte_mask) == 0); + } else { + VERIFY((*last & byte_mask) == byte_mask); + } + } if constexpr (VALUE) *last |= byte_mask; else @@ -157,9 +178,17 @@ public: void set_range(size_t start, size_t len, bool value) { if (value) - set_range<true>(start, len); + set_range<true, false>(start, len); + else + set_range<false, false>(start, len); + } + + void set_range_and_verify_that_all_bits_flip(size_t start, size_t len, bool value) + { + if (value) + set_range<true, true>(start, len); else - set_range<false>(start, len); + set_range<false, true>(start, len); } void fill(bool value) |