AA code 50x slower

evilrat evilrat666 at gmail.com
Sun Feb 16 13:50:49 UTC 2020


On Sunday, 16 February 2020 at 12:57:43 UTC, AlphaPurned wrote:
> template AA(string[] S)
> {
> 	auto _do() { int[string] d; foreach(s; S) d[s] = 0; return d; }
> 	enum AA = _do;
> }
>

My best guess is that enum arrays(except strings) and AA's are 
instantiated every time you access them.
This is especially bad with loops.

Probably you want static or module level variable instead.
Module level AA's can't have compile time initializer, however 
you can do initialization with module constructor instead.
https://dlang.org/spec/module.html#staticorder


More information about the Digitalmars-d-learn mailing list