lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jan 30, 2014 at 6:47 PM, William Ahern
<william@25thandclement.com> wrote:
> On Thu, Jan 30, 2014 at 04:54:25PM -0800, Josh Haberman wrote:
>> If you optimize this pattern enough, you start getting to the point
>> where the malloc/GC/cache effects of allocating a new "row" every time
>> start to become significant.
>
> The idiomatic way to do this, based on several different libraries I've
> seen, is to add a mode where the iterator returns a list of values on the
> stack, rather than stuffing everything into a table. Have the iterator
> function take a possibly empty list of key arguments. If the list is empty,
> just return a row. This is the "convenience" mode. If the list is not empty,
> then it's a list of values to return.

Yes I like this pattern, though it doesn't generalize as well in the
sense that you can't call utility functions that take a "row" as an
argument. But I do like it.

I would love pointers to any of the libraries you've seen that do this.