I was tying to optimize a piece of code that has this construct:
while (i > 0) do begin
Dec(i);
This looks inefficient, so I tried to do this:
while (Dec(i) >= 0) do begin
That doesn’t work because Dec is a procedure and not a function.
So I rewrite it to:
procedure Withloop;
var
....
function Decr(var a: integer): integer; inline;
begin
Dec(a);
Result:= a;
end;
...
while (Decr(i) >= 0) do begin
But this gets compiled into:
SDIMAIN.pas.448: while (Decr(i) >= 0) do begin
00468EE5 8BC4 mov eax,esp
00468EE7 E8D0FEFFFF call Decr <<--- A call??
00468EEC 85C0 test eax,eax
00468EEE 0F8D12FFFFFF jnl $00468e06
00468EF4 EB01 jmp $00468ef7
However in another part of the program, it inlines a function just fine.
What rule of thumb (or hard rule) can I use to know to Delphi will honor the inline directive?
The
Delphi Documentationenumerates the conditions under which inlining does or does not occur:In your case check this condition: