I still don't know what type of optimization would be used. This code might as well look like this:
function UTF8CodepointSizeFast(p: PChar): integer;
begin
case p^ of
#0 .. #191: Result := 1;
#192 .. #223: Result := 2;
#224 .. #239: Result := 3;
#240 .. #247: Result := 4;
#248 .. #255: Result := 1;
end;
end;
The order is correct, the full range of byte values has been used. A redundant compiler message about a possible missing result does not bother (although such a case does not exist for single-byte
Char). So what advantage does the
else version give in practice (at the asm level and various optimizations)?
function UTF8CodepointSizeFast(p: PChar): integer;
begin
case p^ of
#0 .. #191: Result := 1;
#192 .. #223: Result := 2;
#224 .. #239: Result := 3;
#240 .. #247: Result := 4;
else
Result := 1;
end;
end;
Does it even matter?