Optimize away immediately-called delegate literals?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Mar 10 22:51:11 PST 2012


On Sun, Mar 11, 2012 at 01:29:01AM -0500, Nick Sabalausky wrote:
> Suppose you have a delegate literal and immediately call it:
> 
> auto a = x + (){ doStuff(); return y; }() + z;
> 
> Does DMD ever (or always?) optimize away a delegate if it's executed
> immediately and never stored into a variable? If not, can it, and
> would it be a simple change? Is something like this already on the
> table?
[...]

I've always wondered about whether delegates passed to opApply ever get
inlined. Seems to be pretty silly to do the entire function pointer +
context pointer and full function call thing, if both opApply and the
delegate are very simple. Especially if opApply is not much more than a
for loop of some sort, perhaps with a line or two of private member
access code inserted.


T

-- 
Never ascribe to malice that which is adequately explained by
incompetence. -- Napoleon Bonaparte


More information about the Digitalmars-d mailing list