assert!(slice.len() >= SOMETHING);
let _ = slice[0];
let _ = slice[1..N];
...and emit only one bounds check (for the initial assert!) instead of one per index/slice operation. We make heavy use of individual/slice indexing throughout the mapper, so we should use assert! judiciously wherever we can.
That being said, we should make sure that our current pattern isn't already providing this optimization, namely:
if fields.len() < 10 {
return Err(FunctionError::TooShort(fields.len()));
}
rustc
can recognize the following pattern:...and emit only one bounds check (for the initial
assert!
) instead of one per index/slice operation. We make heavy use of individual/slice indexing throughout the mapper, so we should useassert!
judiciously wherever we can.That being said, we should make sure that our current pattern isn't already providing this optimization, namely: