| |
| Posted by Manu in reply to IchorDev | PermalinkReply |
|
Manu
Posted in reply to IchorDev
| On Sat, 24 Aug 2024 at 21:46, IchorDev via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
> On Saturday, 24 August 2024 at 09:11:34 UTC, user1234 wrote:
> > On Saturday, 24 August 2024 at 08:06:21 UTC, IchorDev wrote:
> >> I think everyone in this thread can agree that we need a
> >> compiler-agnostic solution for changing the presumed hot-path,
> >> and one that doesn’t require rewriting existing code more than
> >> just adding on one word. For example, `if((x ==
> >> y).expect(false)){}` makes it a pain to rewrite existing
> >> `if`s, where `@unlikely if(x == y) {}` is easy.
> >
> > You also have the `pragma` option. I think that would be more adequate as not every vendor has to support it. In other words "dmd can just ignore it". Bonus: pragma can be attached to statements, that's not the case of attributes.
>
> Like `pragma(likely, false)`? It’s a bit long, maybe
> `pragma(unlikely)`? It’s something I’d want to use fairly often,
> after all. Or we could just add some new grammar for adding
> special modifiers to if statements. Something like…
> ```d
> if: unlikely(x){
> //…
> }
> if(!x){
> //…
> }else: likely{
> //…
> }
> ```
>
C++ is way ahead on this... they added attributes to the language years
back, and they defined [[likely]] and [[unlikely]] post-fix on control
statements. It's really convenient, it reads well, and it's easy to
retrofit without disturbing the code.
That's the de-facto now, and we should follow it.
|