Help with Template Code
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Apr 1 10:40:37 PDT 2007
"Max Samukha" <samukha at voliacable.com> wrote in message
news:nmmv03h5g5mtbkn6hetbnu33ei6nnnhd67 at 4ax.com...
> I thought it should, too. But when tested on Windows with dmd 1.010,
> the tuple version is significantly slower. I'm still not sure why.
Ahh, looking at the disassembly it makes sense now. What happens is that
when you write:
foreach(i, arg; args)
t.tupleof[i] = arg;
It gets turned into something like _this_:
typeof(args[0]) arg0 = args[0];
t.tupleof[0] = arg0;
typeof(args[1]) arg1 = args[1];
t.tupleof[1] = arg1;
typeof(args[2]) arg2 = args[2];
t.tupleof[2] = arg2;
Notice it copies the argument value into a temp variable, then that temp
variable into the struct. Very inefficient.
Unfortunately I don't know of any way to get around this.. I was hoping
t.tupleof[] = args[];
would work, but it's illegal.
A static for loop would be nice.
More information about the Digitalmars-d-learn
mailing list