Can you shrink it further?
Stefan Koch via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 10 18:39:37 PDT 2016
This version has 24 instructions but these have a smaller
encoding then and are generally inexpensive
With inline asm and conditional moves it would be possible to
reduce this even further
to ~20 instructions.
void popFront1(ref char[] s) @trusted pure nothrow {
immutable c = s[0];
size_t char_length = 1;
if (c < 127)
{
goto Lend;
} else {
if ((c & 0b1100_0000) == 0b1000_0000)
{
// This is invalid as a first char
goto Lerror;
}
if (c < 192)
{
char_length = 2;
goto Lend;
}
if (c < 240) {
char_length = 3;
goto Lend;
}
if (c < 248) {
char_length = 4;
goto Lend;
}
//These characters are also no longer valid
Lerror : assert(0);
}
Lend :
s = s.ptr[char_length .. s.length];
}
More information about the Digitalmars-d
mailing list