Refactors out `unsafe` from MmapAccountHashesFile::read() (#33266)
This commit is contained in:
parent
d4946ddfaa
commit
4c42413c1f
|
@ -42,12 +42,9 @@ impl MmapAccountHashesFile {
|
|||
/// return a slice of account hashes starting at 'index'
|
||||
fn read(&self, index: usize) -> &[Hash] {
|
||||
let start = std::mem::size_of::<Hash>() * index;
|
||||
let item_slice: &[u8] = &self.mmap[start..self.count * std::mem::size_of::<Hash>()];
|
||||
let remaining_elements = item_slice.len() / std::mem::size_of::<Hash>();
|
||||
unsafe {
|
||||
let item = item_slice.as_ptr() as *const Hash;
|
||||
std::slice::from_raw_parts(item, remaining_elements)
|
||||
}
|
||||
let end = std::mem::size_of::<Hash>() * self.count;
|
||||
let bytes = &self.mmap[start..end];
|
||||
bytemuck::cast_slice(bytes)
|
||||
}
|
||||
|
||||
/// write a hash to the end of mmap file.
|
||||
|
|
Loading…
Reference in New Issue