diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index 54dfb2f43a50c5..f83eade4b39004 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -289,18 +289,6 @@ impl BucketStorage { unsafe { slice.get_unchecked_mut(0) } } - pub(crate) fn get_mut_from_parts(item_slice: &mut [u8]) -> &mut T { - debug_assert!(std::mem::size_of::() <= item_slice.len()); - let item = item_slice.as_mut_ptr() as *mut T; - unsafe { &mut *item } - } - - pub(crate) fn get_from_parts(item_slice: &[u8]) -> &T { - debug_assert!(std::mem::size_of::() <= item_slice.len()); - let item = item_slice.as_ptr() as *const T; - unsafe { &*item } - } - pub(crate) fn get_slice(&self, ix: u64, len: u64, header: IncludeHeader) -> &[T] { let start = self.get_start_offset(ix, header); let slice = { diff --git a/bucket_map/src/index_entry.rs b/bucket_map/src/index_entry.rs index 279ac392a1de8a..97915cdc392d98 100644 --- a/bucket_map/src/index_entry.rs +++ b/bucket_map/src/index_entry.rs @@ -46,19 +46,16 @@ pub struct BucketWithHeader { impl BucketOccupied for BucketWithHeader { fn occupy(&mut self, element: &mut [u8], ix: usize) { assert!(self.is_free(element, ix)); - let entry: &mut DataBucketRefCountOccupiedHeader = - BucketStorage::::get_mut_from_parts(element); + let entry = get_mut_from_bytes::(element); entry.packed_ref_count.set_occupied(OCCUPIED_OCCUPIED); } fn free(&mut self, element: &mut [u8], ix: usize) { assert!(!self.is_free(element, ix)); - let entry: &mut DataBucketRefCountOccupiedHeader = - BucketStorage::::get_mut_from_parts(element); + let entry = get_mut_from_bytes::(element); entry.packed_ref_count.set_occupied(OCCUPIED_FREE); } fn is_free(&self, element: &[u8], _ix: usize) -> bool { - let entry: &DataBucketRefCountOccupiedHeader = - BucketStorage::::get_from_parts(element); + let entry = get_from_bytes::(element); entry.packed_ref_count.occupied() == OCCUPIED_FREE } fn offset_to_first_data() -> usize { @@ -426,6 +423,18 @@ impl IndexEntryPlaceInBucket { } } +fn get_from_bytes(item_slice: &[u8]) -> &T { + debug_assert!(std::mem::size_of::() <= item_slice.len()); + let item = item_slice.as_ptr() as *const T; + unsafe { &*item } +} + +fn get_mut_from_bytes(item_slice: &mut [u8]) -> &mut T { + debug_assert!(std::mem::size_of::() <= item_slice.len()); + let item = item_slice.as_mut_ptr() as *mut T; + unsafe { &mut *item } +} + #[cfg(test)] mod tests { use super::*;