Skip to content

Commit

Permalink
fix(kernel): just use core's checked_ilog (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Nov 16, 2022
1 parent 7994b43 commit 2a20199
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use hal_core::{
PAddr,
};
use mycelium_alloc::{buddy, bump};
use mycelium_util::{fmt, math::Logarithm};
use mycelium_util::fmt;

#[derive(Debug)]
pub struct Allocator {
Expand Down Expand Up @@ -171,7 +171,10 @@ impl fmt::Display for State {
if bump_mode {
writeln!(f, " bump allocator mode only")?;
} else {
let digits = (heap_size).checked_ilog(10).unwrap_or(0) + 1;
let digits = {
let digits = (heap_size).checked_ilog(10).unwrap_or(0) + 1;
digits as usize
};
let free = heap_size - allocated;
writeln!(f, "buddy heap:")?;

Expand All @@ -188,7 +191,10 @@ impl fmt::Display for State {
}

writeln!(f, "bump region:")?;
let bump_digits = (bump_size).checked_ilog(10).unwrap_or(0) + 1;
let bump_digits = {
let digits = (bump_size).checked_ilog(10).unwrap_or(0) + 1;
digits as usize
};
let bump_free = bump_size - bump_allocated;

writeln!(f, " {bump_free:>digits$} B free", digits = bump_digits)?;
Expand Down

0 comments on commit 2a20199

Please sign in to comment.