summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authornimelehin <nimelehin@gmail.com>2020-02-28 14:05:22 +0300
committerAndreas Kling <kling@serenityos.org>2020-04-06 08:27:17 +0200
commit73901c9b2bd08efb2bc9a7cfdf2bb1d6b11f2e2f (patch)
tree643823abf671c16111f3091038e9c51ac05d77c3 /AK
parent6e7713a5f4bda99db6ecb809951d235f46bdd59e (diff)
downloadserenity-73901c9b2bd08efb2bc9a7cfdf2bb1d6b11f2e2f.zip
AK: Add Bitmap::set_range()
Add set_range() which sets a range of bits to requested value. Fix code style.
Diffstat (limited to 'AK')
-rw-r--r--AK/Bitmap.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/AK/Bitmap.h b/AK/Bitmap.h
index 92e7c4c890..b285796ea9 100644
--- a/AK/Bitmap.h
+++ b/AK/Bitmap.h
@@ -94,6 +94,12 @@ public:
else
m_data[index / 8] &= static_cast<u8>(~(1u << (index % 8)));
}
+ void set_range(size_t start, size_t len, bool value)
+ {
+ for (size_t index = start; index < start + len; ++index) {
+ set(index, value);
+ }
+ }
u8* data() { return m_data; }
const u8* data() const { return m_data; }
@@ -136,8 +142,7 @@ public:
while (i < m_size / 8 && m_data[i] == 0x00)
i++;
- size_t j = 0;
- for (j = i * 8; j < m_size; j++) {
+ for (size_t j = i * 8; j < m_size; j++) {
if (get(j))
return j;
}
@@ -151,8 +156,7 @@ public:
while (i < m_size / 8 && m_data[i] == 0xff)
i++;
- size_t j = 0;
- for (j = i * 8; j < m_size; j++)
+ for (size_t j = i * 8; j < m_size; j++)
if (!get(j))
return j;