As an aside, I seem to recall .NET making an interesting optimisation here, such that if you access an array using, for example, `data[20]`, bounds checks are omitted for lower indexes.
[1]: https://github.com/rust-lang/rust/blob/f0b58fcf03391a91f7422...
fn loop(a: &[u8]) {
assert!(a.len >= 20);
for x in (0..20) {
let y = a[i];
//Do something with y
}
}
Adding the assert before the loop will remove the bounds checks happening on each iteration.