[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Loop optimization for pairs and ipairs
- From: Xmilia Hermit <xmilia.hermit@...>
- Date: Tue, 7 Jun 2022 23:17:56 +0200
Sean Conner:
Is this safe? I ask because I use the to-be-closed slot in a C module
for use with pairs.
Yes, it only is done in Lua code and if the to-be-closed variable is not used.
To be more precise, for this optimization to trigger the loop setup needs to result in:
pairs: next, table, nil, nil
ipairs: ipairsaux, table, integer, nil
In both cases the to-be-closed variable needs to be nil. If a custome setup function would use the next function but supply a to-be-closed variable the optimisation would not trigger.
The linked function would just use the default path since the iteration function is neither next nor ipairsaux and the to-be-closed variable is also not nil.
Regards,
Xmilia