From 73901c9b2bd08efb2bc9a7cfdf2bb1d6b11f2e2f Mon Sep 17 00:00:00 2001 From: nimelehin Date: Fri, 28 Feb 2020 14:05:22 +0300 Subject: [PATCH] AK: Add Bitmap::set_range() Add set_range() which sets a range of bits to requested value. Fix code style. --- AK/Bitmap.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AK/Bitmap.h b/AK/Bitmap.h index 92e7c4c8900..b285796ea95 100644 --- a/AK/Bitmap.h +++ b/AK/Bitmap.h @@ -94,6 +94,12 @@ public: else m_data[index / 8] &= static_cast(~(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;