Does D have too many features?
deadalnix
deadalnix at gmail.com
Mon Apr 30 05:16:55 PDT 2012
Le 30/04/2012 04:52, H. S. Teoh a écrit :
> 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
>
It is an implementation issue (a real and serious one, but still). It
should be fixed by implementation, not language design.
More information about the Digitalmars-d
mailing list