Reducing the cost of autodecoding
Uplink_Coder via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 15 11:40:11 PDT 2016
It can also be written like this producing smaller code.
But it the cost of slower decoding.
dchar myFront(ref char[] str) pure
{
dchar c = cast(dchar) str.ptr[0];
if (c & 128)
{
if (c & 64)
{
int idx = 0;
int l = charWidthTab.ptr[c - 192];
if (str.length < l)
goto Linvalid;
c = 0;
l--;
while(l) {
l--;
c |= str.ptr[idx++];
c <<= 6;
}
c |= str.ptr[idx];
}
else
Linvalid : throw new Exception("yadayada");
}
return c;
}
More information about the Digitalmars-d
mailing list