From d1678f5a96563d6c60c3da4df7b4c97b6c1e3c29 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 22 Jan 2020 11:35:29 +0100 Subject: [PATCH] Implement `align_up` using `align_offset` from Rust's standard library --- src/allocator.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 9ce4a887..5472e9d4 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -74,11 +74,8 @@ impl Locked { } } +/// Align the given address `addr` upwards to alignment `align`. fn align_up(addr: usize, align: usize) -> usize { - let remainder = addr % align; - if remainder == 0 { - addr // addr already aligned - } else { - addr - remainder + align - } + let offset = (addr as *const u8).align_offset(align); + addr + offset }