3 ms·
In case anyone is interested, rust has unsafe methods to index arrays without bounds checking: https://doc.rust-lang.org/std/primitive.slice.html#method.get_un
by Diggsey 7y ago
In case anyone is interested, rust has unsafe methods to index arrays without bounds checking:
https://doc.rust-lang.org/std/primitive.slice.html#method.get_unchecked https://doc.rust-lang.org/std/primitive.slice.html#method.ge...
- hossbeast 7y agoSounds much worse than the compile time flag.
- Diggsey 7y agoNot really: indexing out of bounds without this check would invoke undefined behaviour. A compile time flag would not be able to distinguish the cases where a bounds check is required for the program to be correct, from the cases where the index is provably within bounds and so is unnecessary. Who wants a compile-time flag that makes valid programs have undefined behaviour? Nobody, especially when you consider that UB in any language really does mean undefined: in the best case the program crashes, in the worst it deletes all your files. What's wanted is a way to tell the compiler "no, in this specific case which I have determined to be a bottleneck in my program, I want to omit bounds checking because due to XYZ it's impossible for the index to ever be out of bounds" and that's exactly what this method provides.