In situations where the programmer needs the efficiency gained by skipping the bounds check of arr[i]
(assuming they know for sure that i
will always be within bounds of arr
, but the optimizer has no way of proving it), is there a way to do eg:
arr[unchecked: i]
?
If not, would it make sense to add a subscript like that to Array
and ContiguousArray
or is there some other recommended way (without using pointers instead of arrays or doing an unchecked build)?
Perhaps the following will get the element at index i
without any overhead (assuming release mode):
arr.withUnsafeBufferPointer { $0[i] }
?