Skip to content

Commit

Permalink
stats: explictly do get_unchecked_mut instead of depending on
Browse files Browse the repository at this point in the history
assert hoping compiler does not do unneeded index validation
  • Loading branch information
jqnatividad committed Jun 1, 2024
1 parent a2da7c1 commit df769e4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,13 @@ impl Args {
.unwrap();
});
}
assert!(results.len() == records.len());
for (i, recv) in results.into_iter().enumerate() {
// safety: the assert above guarantees that records index access is safe and
// doesn't require a bounds check.
// safety: results.len() == records.len() so we know the index is valid
// and doesn't require a bounds check.
// The unwrap on recv.recv() is safe as the channel is bounded
records[i] = recv.recv().unwrap();
unsafe {
*records.get_unchecked_mut(i) = recv.recv().unwrap();
}
}
records
}
Expand Down

0 comments on commit df769e4

Please sign in to comment.