Skip to content

Commit

Permalink
stats: use unwrap_unchecked instead of unwrap in perf-critical hot …
Browse files Browse the repository at this point in the history
…loop

we already use unwrap amyway, might as well use unwrap_unchecked for stuff we know will not panic to get rid of panic code
  • Loading branch information
jqnatividad committed Oct 19, 2024
1 parent f205809 commit e26c27f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,19 @@ impl Args {
// if it does return an Err, you have a bigger problem as the index file was
// modified WHILE stats is running and you NEED to abort if that
// happens, however unlikely
let mut idx = args.rconfig().indexed().unwrap().unwrap();
let mut idx = unsafe {
args.rconfig()
.indexed()
.unwrap_unchecked()
.unwrap_unchecked()
};
idx.seek((i * chunk_size) as u64)
.expect("File seek failed.");
let it = idx.byte_records().take(chunk_size);
// safety: this will only return an Error if the channel has been disconnected
send.send(args.compute(&sel, it)).unwrap();
unsafe {
send.send(args.compute(&sel, it)).unwrap_unchecked();
}
});
}
drop(send);
Expand Down

0 comments on commit e26c27f

Please sign in to comment.