diff --git a/runtime/src/cache_hash_data.rs b/runtime/src/cache_hash_data.rs index 4071d9cd2c89fa..c5b92c71b95dee 100644 --- a/runtime/src/cache_hash_data.rs +++ b/runtime/src/cache_hash_data.rs @@ -50,6 +50,24 @@ impl CacheHashDataFile { } } + fn get(&self, ix: u64) -> &T { + let start = (ix * self.cell_size) as usize + std::mem::size_of::
(); + let end = start + std::mem::size_of::(); + assert!( + end <= self.capacity as usize, + "end: {}, capacity: {}, ix: {}, cell size: {}", + end, + self.capacity, + ix, + self.cell_size + ); + let item_slice: &[u8] = &self.mmap[start..end]; + unsafe { + let item = item_slice.as_ptr() as *const T; + &*item + } + } + fn get_header_mut(&mut self) -> &mut Header { let start = 0_usize; let end = start + std::mem::size_of::
(); @@ -228,7 +246,7 @@ impl CacheHashData { stats.entries_loaded_from_cache += entries; let mut m2 = Measure::start("decode"); for i in 0..entries { - let d = cache_file.get_mut::(i as u64); + let d = cache_file.get::(i as u64); let mut pubkey_to_bin_index = bin_calculator.bin_from_pubkey(&d.pubkey); assert!( pubkey_to_bin_index >= start_bin_index,