News for hackers. Stuff that matters.
Re:Impact of Undefined Behavior on Performance by the8472 on Friday July 09, 2021 @07:57AM (#27782765)
Safe rust can eliminate the loop just fine if you use fold() or an exclusive range instead of an inclusive one. This is because in release mode it has wrapping semantics for unsigned integers. In debug mode you would get a panic instead for too large inputs. So the behavior is defined, albeit still a bit of a pitfall. But you can enable overflow checks in release mode too if desired.

https://rust.godbolt.org/z/1sK7GEr9E

There are no comments on this comment yet.