bucket_map: Moves get_from_bytes() to index_entry.rs (#31443)
This commit is contained in:
parent
9b6cadc102
commit
1a6c75a115
|
@ -289,18 +289,6 @@ impl<O: BucketOccupied> BucketStorage<O> {
|
|||
unsafe { slice.get_unchecked_mut(0) }
|
||||
}
|
||||
|
||||
pub(crate) fn get_mut_from_parts<T>(item_slice: &mut [u8]) -> &mut T {
|
||||
debug_assert!(std::mem::size_of::<T>() <= item_slice.len());
|
||||
let item = item_slice.as_mut_ptr() as *mut T;
|
||||
unsafe { &mut *item }
|
||||
}
|
||||
|
||||
pub(crate) fn get_from_parts<T>(item_slice: &[u8]) -> &T {
|
||||
debug_assert!(std::mem::size_of::<T>() <= item_slice.len());
|
||||
let item = item_slice.as_ptr() as *const T;
|
||||
unsafe { &*item }
|
||||
}
|
||||
|
||||
pub(crate) fn get_slice<T>(&self, ix: u64, len: u64, header: IncludeHeader) -> &[T] {
|
||||
let start = self.get_start_offset(ix, header);
|
||||
let slice = {
|
||||
|
|
|
@ -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::<BucketWithHeader>::get_mut_from_parts(element);
|
||||
let entry = get_mut_from_bytes::<DataBucketRefCountOccupiedHeader>(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::<BucketWithHeader>::get_mut_from_parts(element);
|
||||
let entry = get_mut_from_bytes::<DataBucketRefCountOccupiedHeader>(element);
|
||||
entry.packed_ref_count.set_occupied(OCCUPIED_FREE);
|
||||
}
|
||||
fn is_free(&self, element: &[u8], _ix: usize) -> bool {
|
||||
let entry: &DataBucketRefCountOccupiedHeader =
|
||||
BucketStorage::<BucketWithHeader>::get_from_parts(element);
|
||||
let entry = get_from_bytes::<DataBucketRefCountOccupiedHeader>(element);
|
||||
entry.packed_ref_count.occupied() == OCCUPIED_FREE
|
||||
}
|
||||
fn offset_to_first_data() -> usize {
|
||||
|
@ -426,6 +423,18 @@ impl<T: Copy + 'static> IndexEntryPlaceInBucket<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_from_bytes<T>(item_slice: &[u8]) -> &T {
|
||||
debug_assert!(std::mem::size_of::<T>() <= item_slice.len());
|
||||
let item = item_slice.as_ptr() as *const T;
|
||||
unsafe { &*item }
|
||||
}
|
||||
|
||||
fn get_mut_from_bytes<T>(item_slice: &mut [u8]) -> &mut T {
|
||||
debug_assert!(std::mem::size_of::<T>() <= item_slice.len());
|
||||
let item = item_slice.as_mut_ptr() as *mut T;
|
||||
unsafe { &mut *item }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in New Issue