== Quote from dsimcha ([email protected])'s article > == Quote from Andrei Alexandrescu ([email protected])'s > > Lest a misunderstanding arises, the code: > > auto r = map!((float a) { return fabs(a); })(a); > > does *not* involve a delegate; it's still a direct call. This code > > doesn't currently compile because of a bug in the compiler, but this > > equivalent code does: > > float fun(float a) { return fabs(a); } > > auto r = map!(fun)(a); > > and again it does not involve a delegate. > But, for the truly performance obsessed, it's still a non-static nested > function > that doesn't access any local variables in the outer scope. Isn't it still > taking > a pointer to the outer scope as an implicit argument, kind of like a this > pointer, > or are real-world compilers sufficiently smart to optimize that out if you > never > use any of the variables in the outer scope? > Yes, I know this is nitpicking, but I'm asking primarily out of curiosity > rather > than out of practical concern. I also realize that, if you really care that > much, > you can declare fun() as static and get rid of the implicit pointer to the > outer > scope. This is kind of ugly, but I guess code that's this micro-optimized is > going to be ugly any way you cut it.
To answer my own question, I benchmarked this using a sorting function, and it doesn't matter in practice, probably because DMD is smart enough to inline simple nested functions. As a positive control (to make sure the benchmark is valid), when I explicitly made the alias a function _pointer_ instead of a function _name_, this made a fairly large difference.
