[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Loop optimization for pairs and ipairs
- From: Sean Conner <sean@...>
- Date: Tue, 7 Jun 2022 17:04:22 -0400
It was thus said that the Great Xmilia Hermit once stated:
> Hi,
>
> I want to share a patch to optimize for-in loops for the pairs and
> ipairs case. It is inspired by LuaJITs ITERN optimization and a similar
> optimization in Luau.
>
> It works by checking in the OP_TFORPREP opcode for the pairs and ipairs
> case and use the to-be-closed slot for an index variable in the pairs
> and a marker in the ipairs case.
Is this safe? I ask because I use the to-be-closed slot in a C module
[1] for use with pairs.
-spc
[1] https://github.com/spc476/lua-conmanorg/blob/98f37deafb43d5d59fe1f2039c3bfc5575fce202/src/fsys.c#L638