Implement align_up using align_offset from Rust's standard library (#723)

Improve `align_up` performance using a bitmask
This commit is contained in:
Philipp Oppermann
2020-01-28 10:39:14 +01:00
committed by GitHub

View File

@@ -74,11 +74,9 @@ impl<A> Locked<A> {
}
}
/// Align the given address `addr` upwards to alignment `align`.
///
/// Requires that `align` is a power of two.
fn align_up(addr: usize, align: usize) -> usize {
let remainder = addr % align;
if remainder == 0 {
addr // addr already aligned
} else {
addr - remainder + align
}
(addr + align - 1) & !(align - 1)
}