[fpc-pascal] Inline methods

LacaK lacak at zoznam.sk
Wed May 18 11:54:06 CEST 2016


> > > is it possible inline also methods of objects (not regular 
> procedures) ?
> > > I have very simple class method, which call I need inline.
> > > (looking at assembler code it is not inlined; I have looked also 
> in documentation, but I do not found article about inline and methods)
> > >
> > > Example:
> > >
> > > function T2DArray.Data(x, y: integer): PElement; inline;
> > > begin
> > >   Result := @FArray[x+y*Fx];
> > > end;
> >
> > Yes. Inline needs to be declared at the declaration however and not 
> the implementation
>
I have "inline" on both places also on declaration

> and any function or method that uses it (in the same unit) needs to 
> come afterwards
>
Yes it comes afterwards

> if you want it to be inlined (for other units that doesn't matter as 
> long as you don't have circular dependencies, cause then things get 
> messy). On addition to that "inline" is only a hint for the compiler, 
> so there might be cases when the compiler decides not to inline.
>
> Oh and it obviously won't work with virtual methods.
>
In my case it is not virtual method.

But I forgot to mention, that it is method of generic object:

   generic T2DArray<T> = object
    ...
     public
       constructor Init(oobMode: TOutOfBoundsMode); overload;
       constructor Init(x,y: integer); overload;
       ...
       function Data(x,y: integer): PElement; overload; inline;
   end;

So what can be a case, that method is not inlined, can it be track down 
or is there something which I can do to force inlining ?
(FPC 2.6.4)
Thanks
-Laco.



More information about the fpc-pascal mailing list