Reducing the cost of autodecoding

Uplink_Coder via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 15 12:42:03 PDT 2016


On Saturday, 15 October 2016 at 19:07:50 UTC, Patrick Schluter 
wrote:
> At least with that lookup table below, you can detect isolated 
> continuation bytes (192 and 193) and invalid codes (above 244).
>
> __gshared static immutable ubyte[] charWidthTab = [
>             1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
>             2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
>             3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
>             4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
> ];
>
> length 5 and 6 need not to be tested specifically for your goto.

If you use 0 instead of 1 the length check will suffice for 
throwing on invalid.



More information about the Digitalmars-d mailing list