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'
|
/// return a slice of account hashes starting at 'index'
|
||||||
fn read(&self, index: usize) -> &[Hash] {
|
fn read(&self, index: usize) -> &[Hash] {
|
||||||
let start = std::mem::size_of::<Hash>() * index;
|
let start = std::mem::size_of::<Hash>() * index;
|
||||||
let item_slice: &[u8] = &self.mmap[start..self.count * std::mem::size_of::<Hash>()];
|
let end = std::mem::size_of::<Hash>() * self.count;
|
||||||
let remaining_elements = item_slice.len() / std::mem::size_of::<Hash>();
|
let bytes = &self.mmap[start..end];
|
||||||
unsafe {
|
bytemuck::cast_slice(bytes)
|
||||||
let item = item_slice.as_ptr() as *const Hash;
|
|
||||||
std::slice::from_raw_parts(item, remaining_elements)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// write a hash to the end of mmap file.
|
/// write a hash to the end of mmap file.
|
||||||
|
|
Loading…
Reference in New Issue