Skip to content

Commit b6d7c66

Browse files
utils: fix find_first_unset in bitmap
Signed-off-by: Anhad Singh <[email protected]>
1 parent 4a96fe6 commit b6d7c66

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/aero_kernel/src/utils/bitmap.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,18 @@ impl<A: Allocator> Bitmap<A> {
100100
for (i, block) in self.bitmap.iter().enumerate() {
101101
let mut block_value = *block;
102102

103-
if block_value == 0 {
104-
return Some(i * BLOCK_BITS);
105-
}
103+
if block_value != usize::MAX {
104+
let mut bit = 0;
106105

107-
let mut bit = 0;
106+
// Loop through the bits in the block and find
107+
// the first unset bit.
108+
while block_value.get_bit(0) {
109+
block_value >>= 1;
110+
bit += 1;
111+
}
108112

109-
// Loop through the bits in the block and find
110-
// the first unset bit.
111-
while block_value.get_bit(0) {
112-
block_value >>= 1;
113-
bit += 1;
113+
return Some((i * BLOCK_BITS) + bit);
114114
}
115-
116-
return Some((i * BLOCK_BITS) + bit);
117115
}
118116

119117
None

0 commit comments

Comments
 (0)