Skip to content

Commit

Permalink
get rid of unnecessary mut
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Sep 23, 2022
1 parent a846d50 commit e513da1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion runtime/src/cache_hash_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ impl CacheHashDataFile {
}
}

fn get<T: Sized>(&self, ix: u64) -> &T {
let start = (ix * self.cell_size) as usize + std::mem::size_of::<Header>();
let end = start + std::mem::size_of::<T>();
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::<Header>();
Expand Down Expand Up @@ -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::<EntryType>(i as u64);
let d = cache_file.get::<EntryType>(i as u64);
let mut pubkey_to_bin_index = bin_calculator.bin_from_pubkey(&d.pubkey);
assert!(
pubkey_to_bin_index >= start_bin_index,
Expand Down

0 comments on commit e513da1

Please sign in to comment.