On Sun, Apr 29, 2012 at 10:03:43AM +0400, Dmitry Olshansky wrote: > On 29.04.2012 5:06, bearophile wrote: [...] > >Loops _must_ be fully efficient, they are a basic language construct, > >this is very important. Even foreach() is sometimes not equally > >efficient as a for() in some cases... > > > Doesn't have to do anything with the LANGUAGE. > Yesterday I tried GDC. Damn I didn't regret it :) [...]
Unfortunately, even GDC doesn't inline opApply and its delegate for the simplest of loops: struct S { int data[]; int opApply(int delegate(ref int) dg) { foreach (d; data) { if (auto r = dg(d)) return r; } return 0; } } void main() { S s; foreach (e; s) { writeln(e); } } I think it's because the front-end always generates the full delegate passing code without inlining anything. IMO, this case *need* to be aggressively inlined in order to make D's generic programming capabilities a stronger selling point. T -- "Computer Science is no more about computers than astronomy is about telescopes." -- E.W. Dijkstra