September 03, 2014
On Wednesday, 3 September 2014 at 21:00:13 UTC, deadalnix wrote:
> On Wednesday, 3 September 2014 at 06:37:15 UTC, Iain Buclaw via
> Digitalmars-d wrote:
>> For the time being, they are as expensive as virtual calls.
>>
>> Iain.
>
> WUT ???
>
> How come ? The address of the call is know at compile time, the
> optimizer should see through this, no ?

Iain is selling his compiler short again. ;)

---
int foo(int[] a) @safe {
  if (a.length == 0) return -1;
  return (() @trusted => a.ptr[0])();
}
---
compiles to exactly what you would expect when optimizations are enabled with both GDC and LDC.

However, as long as DMD can't handle this idiom, there will be push-back regarding use in Phobos. Additionally, we should think about always inlining such literals even on -O0.

Cheers,
David
September 03, 2014
On 3 Sep 2014 23:00, "David Nadlinger via Digitalmars-d" < digitalmars-d@puremagic.com> wrote:
>
> On Wednesday, 3 September 2014 at 21:00:13 UTC, deadalnix wrote:
>>
>> On Wednesday, 3 September 2014 at 06:37:15 UTC, Iain Buclaw via Digitalmars-d wrote:
>>>
>>> For the time being, they are as expensive as virtual calls.
>>>
>>> Iain.
>>
>>
>> WUT ???
>>
>> How come ? The address of the call is know at compile time, the optimizer should see through this, no ?
>
>
> Iain is selling his compiler short again. ;)
>

Always sell short, so they never complain when it does one better (also means you don't overshoot expectations ;)

I am of course going off memory, and there are some very obvious cases with delegates that never get optimized.

Iain.


1 2 3 4 5 6 7 8
Next ›   Last »