> On Jun 19, 2022, at 10:04 PM, Sven Barth <pascaldra...@googlemail.com> wrote:
> 
> As you can see the allocation only happens once and not all the time. 
> What might be worse however is the optimization behavior as in this example 
> the compiler wouldn't optimize the counter variable into a regvar with 
> enabled optimizations (however in case of a nested function the compiler 
> wouldn't do this either if the function isn't inlined). 
> 


I’m saying if the OUTER method is in a tight loop (Foo in this example) you’re 
in trouble because it now contains an allocation which is unexpected. In fact 
if this happened within a class wouldn’t it capture and initialize all the 
classes fields also or does it know to only use the fields which are 
encountered in the function body?

Either way the reference never leaves the calling scope and thus is wasted and 
should be optimized away to something which exists on the stack, like “is 
nested”.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to