Minor optimizations on both lat-syscall-stat and lat-syscall-open

This commit is contained in:
Shaowei Song
2024-09-26 04:03:32 +00:00
committed by Tate, Hongliang Tian
parent fc77c474db
commit f2af6136da
6 changed files with 32 additions and 25 deletions

View File

@ -191,7 +191,7 @@ impl<'a> ReadCString for VmReader<'a, Fallible> {
// Handle the first few bytes to make `cur_addr` aligned with `size_of::<usize>`
read_one_byte_at_a_time_while!(
(self.cursor() as usize) % mem::size_of::<usize>() != 0 && buffer.len() < max_len
!is_addr_aligned(self.cursor() as usize) && buffer.len() < max_len
);
// Handle the rest of the bytes in bulk
@ -253,3 +253,8 @@ fn check_vaddr(va: Vaddr) -> Result<()> {
Ok(())
}
}
/// Checks if the given address is aligned.
const fn is_addr_aligned(addr: usize) -> bool {
(addr & (mem::size_of::<usize>() - 1)) == 0
}