4 ms·
https://rust.godbolt.org/z/zM58dcPse https://rust.godbolt.org/z/zM58dcPse And look, putting a limit that the compiler and guarantee once outside the critical l
by 3836293648 5y ago
https://rust.godbolt.org/z/zM58dcPse https://rust.godbolt.org/z/zM58dcPse
And look, putting a limit that the compiler and guarantee once outside the critical loop eliminates it. You're already using unsafe. If you really want to shoot yourself in the foot with this nonsense you can use a get unchecked or an unchecked assumption
https://rust.godbolt.org/z/naeaYad5T https://rust.godbolt.org/z/naeaYad5T
On top of that, noone would write rust code like that. This version has one bounds check at the beginning and is a lot more idiomatic
https://rust.godbolt.org/z/1s9zsMx36 https://rust.godbolt.org/z/1s9zsMx36
- jcelerier 5y agoThe point is to have some code that exhibits what happens when a bound check is needed. You can also do for(double v : std::span(vec).subspan(1)) { } in C++ and that will be safe and not need a bound check except an user-provided one at the creation of the span (-1 for C++ here :-)) - and also not matter at all regarding the bound checks problem which will occur as soon as you don't just iterate linearly which is extremely common in the kind of problems that end up showing at the top of the profiler and the whole point of this conversation.