[fpc-devel] Little feature teaser

Sven Barth pascaldragon at googlemail.com
Sat Aug 3 13:00:06 CEST 2013


On 03.08.2013 09:36, Sven Barth wrote:
> Am 02.08.2013 23:26 schrieb "Florian Klämpfl" <florian at freepascal.org
> <mailto:florian at freepascal.org>>:
>  >
>  > Am 02.08.2013 17:46, schrieb Sven Barth:
>  > > - using an array declared as a ranged array (array[0..2] of
> LongInt) the
>  > > for-loop is inlined and optimized a bit (especially depending on the
>  > > optimization settings), but the compiler does not yet fold the loop...
>  > >
>  >
>  > At least I fixed loop unrolling for for-in loops.
>
> Cool! I'll need to test that with my test code :)

Hmm... am I expecting too much or is it really not working?

=== code begin ===

program inlinetest;

{$modeswitch result}

type
   TLongIntArray = array[0..2] of LongInt;

function IsIn(aElement: LongInt; const aArray: TLongIntArray): Boolean; 
inline;
var
   element: LongInt;
begin
   for element in aArray do
     if element = aElement then
       Exit(True);
   Result := False;
end;


procedure Test;
const
   MyArray: TLongIntArray = (42, 48, 39);
var
   b: Boolean;
begin
   b := IsIn(42, MyArray);
end;

begin

end.

=== code end ===

Tested with -O2, -O3 and -O4 and in all cases I still have the loop.

Regards,
Sven



More information about the fpc-devel mailing list