if(arr) now a warning
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 10 10:37:42 PDT 2015
On Friday, 10 April 2015 at 17:37:03 UTC, John Colvin wrote:
> On Friday, 10 April 2015 at 11:59:32 UTC, Kagamin wrote:
>> On Friday, 10 April 2015 at 11:39:59 UTC, Vladimir Panteleev
>> wrote:
>>> https://github.com/D-Programming-Language/tools/pull/166/files
>>> I don't know the code well enough to know if arr != null
>>> would be more appropriate.
>>
>> It's probably a nitpick, I like arr!=null expression a lot,
>> but currently compiler generates a horrible code for it: ldc
>> generates comparison with typeinfos, and dmd inlines whole
>> memcmp among other things instead of converting it to just
>> arr.length!=0.
>
> gcc does what you want:
>
> bool foo(int[] a)
> {
> return a != null;
> }
>
> bool bar(int[] a)
> {
> return a.length != 0;
> }
>
> bool example.foo(int[]):
> testq %rdi, %rdi
> setne %al
> ret
> bool example.bar(int[]):
> testq %rdi, %rdi
> setne %al
> ret
Whoops, that should be gdc, not gcc
More information about the Digitalmars-d
mailing list