Templates do maybe not need to be that slow (no promises)

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 9 02:31:37 PDT 2016


Am Fri, 09 Sep 2016 07:56:04 +0000
schrieb Stefan Koch <uplink.coder at googlemail.com>:

> Hi Guys,
> 
> I keep this short.
> There seems to be much more headroom then I had thought.
> 
> The Idea is pretty simple.
> 
> Consider :
> int fn(int padLength)(int a, int b, int c)
> {
>    /**
>     very long function body 1000+ lines
>     */
>    return result * padLength;
> }
> 
> This will produce roughly the same code for every instaniation 
> expect for one imul at the end.
> 
> […]

Don't worry about this special case too much. At least GCC can
turn padLength from a runtime argument into a compile-time
argument itself, so the need for templates to do a poor man's
const-folding is reduced. So in this case the advise is not to
use a template.

You said that there is a lot of code-gen and string
comparisons going on. Is code-gen already invoked on-demand?
I assume with "dmd -o-" code-gen is completely disabled, which
is great for ddoc, .di and dependency graph generation.

-- 
Marco



More information about the Digitalmars-d mailing list