lua-users home
lua-l archive

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


On Wed, Apr 13, 2011 at 15:20, Francesco Abbate <francesco.bbt@gmail.com> wrote:
> 2011/4/13 Henning Diedrich <hd2010@eonblast.com>:
>> This seems to be like the atomic operation for it

>> '[' .. table.concat(t, ',') .. ']'

>> does a subtler approach come to mind for anybody, e.g. drawing more
>> explicitly from LuaJIT's strengths?

> Not related to LuaJIT but I guess the following should be better:

> string.format('[%s]', table.concat(t, ','))

> because it does avoid the creation of unneeded temporary
> strings(expect the one returned by table.concat.

Did you actually profile it?

I bet that in plain Lua version with `string.format` is slower. (One
extra global lookup, one extra table index, one extra function call.)

AFAIR, temporary string would not be created, as string concatenations
will be batched to the same VM instruction.

Alexander.