mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
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.
This commit is contained in:
parent
79ebcacce2
commit
c268df79e6
Notes:
sideshowbarker
2024-07-18 20:37:52 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c268df79e6a
2 changed files with 33 additions and 4 deletions
|
@ -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); }
|
||||
|
|
|
@ -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>(start, len);
|
||||
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, true>(start, len);
|
||||
}
|
||||
|
||||
void fill(bool value)
|
||||
|
|
Loading…
Reference in a new issue