Paulo Pinto:

Am 18.05.2014 10:02, schrieb bearophile:
But in general isn't it more efficient to not generate bloat instead of
generating it, detecting it, and removing it?

Bye,
bearophile

Which you can only do if the compiler can see the whole code.

It doesn't work in binary libraries.

I think in this case avoiding part of the problem is better than avoiding none of it :-) There are other similar situations where avoiding the template bloat is useful. This generates two instances of doubleIt in the binary:


T doubleIt(T)(T x) { return x * 2; }
void main() {
    immutable r1 = doubleIt(10);
    immutable r2 = doubleIt(cast(const int)10);
}


The asm, from DMD:

_D4temp15__T8doubleItTiZ8doubleItFNaNbNiNfiZi:
        enter   4,0
        add EAX,EAX
        leave
        ret

_D4temp16__T8doubleItTxiZ8doubleItFNaNbNiNfxiZxi:
        enter   4,0
        add EAX,EAX
        leave
        ret

Bye,
bearophile

Reply via email to