mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-30 23:02:06 +00:00
18 lines
519 B
Rust
18 lines
519 B
Rust
/// Round `size` up to the nearest multiple of `page_size`.
|
|
pub fn round_up_to_page_size(size: usize, page_size: usize) -> usize {
|
|
(size + (page_size - 1)) & !(page_size - 1)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_round_up_to_page_size() {
|
|
assert_eq!(round_up_to_page_size(0, 4096), 0);
|
|
assert_eq!(round_up_to_page_size(1, 4096), 4096);
|
|
assert_eq!(round_up_to_page_size(4096, 4096), 4096);
|
|
assert_eq!(round_up_to_page_size(4097, 4096), 8192);
|
|
}
|
|
}
|