Standard way to supply hints to branches
Walter Bright
newshound2 at digitalmars.com
Sat Sep 7 20:14:49 UTC 2024
On 9/6/2024 3:21 AM, Quirin Schroll wrote:
> Early returns for unlikely-but-valid input like null pointers
> makes sense to me.
I often write code so that the happy path is the first if. Andrei objected to
this style :-/
> Other than that, there’s `if (...) throw ...;`, but basically
> all optimizers recognize this as an unlikely path.
Sure, but that's only one case. Manu's functions are all nothrow.
> This is your style, and IMO it’s a bad style.
Since CPU branch prediction for forward branches assumes they are not taken, it
seems your style is statistically less likely. (As I assume the CPU designers
did collect statistics on this.)
More information about the Digitalmars-d
mailing list