7 ms·
I think the lines gets blurred when doing early exits and guard conditions. For instance if !condition_a && !conditon_b { return fn_d() // probably an e
by makeitdouble 3y ago
I think the lines gets blurred when doing early exits and guard conditions.
For instance
if !condition_a && !conditon_b {
return fn_d() // probably an error condition ?
}
if condition_a && condition_b {
return fn_a()
}
if condition_a {
fn_b()
} else {
fn_c()
}
- 1letterunixname 3y agoThese 3 examples optimize to the the same thing because they generate identical instructions: https://godbolt.org/z/a1Yq9rceE https://godbolt.org/z/a1Yq9rceE Note: Inverting and rearranging conditions changes what LLVM decides to output, sometimes for the worse. --opt-level=s is counterproductive here.