On Friday, 23 August 2024 at 07:33:53 UTC, Dom DiSc wrote:
>On Friday, 23 August 2024 at 01:47:37 UTC, Manu wrote:
>How can we add an attribute to the branch condition that the backend can take advantage of? I think it needs to be in the language spec...
I always arrange it so, that the if-path is the likely one, and the else path is the unlikely one.
As if anyone can remember that.
>This also makes the code more readable,
Absolutely not. Early returns for unlikely-but-valid input like null pointers makes sense to me. Other than that, there’s if (...) throw ...;
, but basically all optimizers recognize this as an unlikely path.
and it is always possible to do so.
Technically yes, but it makes some code harder to understand.
>The compiler should optimize accordingly. No further indication should be necessary.
This is your style, and IMO it’s a bad style.