As said, I am trying to avoid runtime SizeOf() and case block check.
SizeOf() is never evaluated at runtime, it is a compile-time constant. Thus, in code like this:
function TORDINALHELPER.HighestBitPos: Cardinal;
begin
case SizeOf(TORDINALTYPE) of
1: Result := BsrByte(Byte(Self));
2: Result := BsrWord(Word(Self));
4: Result := BsrDWord(DWord(Self));
8: Result := BsrQWord(QWord(Self));
else
Result := 0;
end;
end;
The
case statement is being passed a constant, so the compiler knows exactly what the value is and can optimize away all of the unused cases at compile-time, thus leaving only the 1 usable case to be executable at runtime.