Add function to calculate the list index

This commit is contained in:
Philipp Oppermann
2020-01-20 14:05:24 +01:00
parent d636939b51
commit 821dd2adb4

View File

@@ -7,6 +7,14 @@ use core::ptr;
/// the block alignment (alignments must be always powers of 2). /// the block alignment (alignments must be always powers of 2).
const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048]; const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048];
/// Choose an appropriate block size for the given layout.
///
/// Returns an index into the `BLOCK_SIZES` array.
fn list_index(layout: &Layout) -> Option<usize> {
let required_block_size = layout.size().max(layout.align());
BLOCK_SIZES.iter().position(|&s| s >= required_block_size)
}
struct ListNode { struct ListNode {
next: Option<&'static mut ListNode>, next: Option<&'static mut ListNode>,
} }