lua-users home
lua-l archive

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


2009/6/26 Vaughan McAlley <ockegheim@gmail.com>:
> 2009/6/26 Peter Cawley <lua@corsix.org>:
>>
>> table.concat (table [, sep [, i [, j]]])
>>
>> unpack (list [, i [, j]])
>>
>> Both of these functions already have optional extra arguments, i and
>> j, which specify the range to operate over. By default they are 1 and
>> #table, but you can pass other values.
>>
>
>> print(table.concat({unpack(t, 1, 3)}))
>
> Touché. I'll have to read through the manual and find all the other
> functions I think I know.

Actually Peter Cawley's solution is even better, I tend to forget
about these extra parameters myself too.

>> Why would you want to recycle a table in the first place without
>> clearing it first ? Assuming you want to avoid table creation because
>> you imagine it's slow, did you benchmark it before asking for a Lua
>> API change ?
>
> I'm using table.concat for creating messages consisting of lots of
> small strings. If I want to create ten messages at a time, recycling
> one table would create less garbage than ten tables, and would save
> clearing the table each time. All this reading the Lua list has made
> me cautious about creating unnecessary tables, even if it hasn't made
> me aware of optional parameters to certain functions.

Did you benchmark your application and measure a noticeable
performance improvement by doing so ?