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

Reply via email to