CTFE Status
Stefan Koch via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 15 15:37:50 PST 2016
On Thursday, 15 December 2016 at 23:05:55 UTC, Dmitry Olshansky
wrote:
>
> Afaik string switches are implemented as a fairly slow hash
> table. Optimal solutions like building a trie would be a nice
> enhancement.
>
> ---
> Dmitry Olshansky
Tries take up alot of memory for sparse tables.
I would like to avoid them.
Futhermore, CTFE is targeted towards smaller functions with low
iteration count.
Therefore producing bytecode as fast as possible is priority.
This function from std.uri does now compile and execute correctly.
private enum
{
URI_Alpha = 1,
URI_Reserved = 2,
URI_Mark = 4,
URI_Digit = 8,
URI_Hash = 0x10, // '#'
}
immutable ubyte[128] uri_flags = // indexed by character
({
ubyte[128] uflags;
// Compile time initialize
uflags['#'] |= URI_Hash;
foreach (c; 'A' .. 'Z' + 1)
{
uflags[c] |= URI_Alpha;
uflags[c + 0x20] |= URI_Alpha; // lowercase letters
}
foreach (c; '0' .. '9' + 1) uflags[c] |= URI_Digit;
foreach (c; ";/?:@&=+$,") uflags[c] |= URI_Reserved;
foreach (c; "-_.!~*'()") uflags[c] |= URI_Mark;
return uflags;
})();
I have to say I was surprised myself :)
It takes around 30 us to execute, which can be improved for sure
:)
More information about the Digitalmars-d
mailing list