From 821dd2adb4de5b378dd5fb2fedaec10fec91b764 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 20 Jan 2020 14:05:24 +0100 Subject: [PATCH] Add function to calculate the list index --- src/allocator/fixed_size_block.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/allocator/fixed_size_block.rs b/src/allocator/fixed_size_block.rs index c83a12cd..df97a118 100644 --- a/src/allocator/fixed_size_block.rs +++ b/src/allocator/fixed_size_block.rs @@ -7,6 +7,14 @@ use core::ptr; /// the block alignment (alignments must be always powers of 2). 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 { + let required_block_size = layout.size().max(layout.align()); + BLOCK_SIZES.iter().position(|&s| s >= required_block_size) +} + struct ListNode { next: Option<&'static mut ListNode>, }