Do you think if statement as expression would be nice to have in D?

SealabJaster sealabjaster at gmail.com
Mon Jun 6 22:26:56 UTC 2022


On Monday, 6 June 2022 at 20:31:06 UTC, deadalnix wrote:
> On Monday, 6 June 2022 at 17:43:47 UTC, H. S. Teoh wrote:
>> On Mon, Jun 06, 2022 at 05:07:30PM +0000, deadalnix via 
>> Digitalmars-d wrote:
>>> [...]
>>>
>>> LDC is able to inline the lambda and then optimize away the 
>>> allocation. DMD is not.
>>> 
>>> https://godbolt.org/z/5vMcz4s14
>>
>> Yeah, when in doubt, trust LDC to do the "right thing". :-P  
>> Well, that, and take a look at the generated assembly to see 
>> what it actually does. For questions of performance or codegen 
>> quality, I usually don't even bother looking at DMD output.
>>
>>
>> T
>
> I mean:
>
> ```
> int example.foo(immutable(char)[]):
>         cmp     rdi, 5
>         jne     .LBB0_3
>         mov     eax, 1764586337
>         xor     eax, dword ptr [rsi]
>         movzx   ecx, byte ptr [rsi + 4]
>         xor     ecx, 115
>         or      ecx, eax
>         je      .LBB0_2
> .LBB0_3:
>         mov     eax, 100
>         ret
> .LBB0_2:
>         mov     eax, 200
>         ret
> ```
>
> It's amazing.

wow wtf :D


More information about the Digitalmars-d mailing list