lua-users home
lua-l archive

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


On Thu, Aug 20, 2009 at 3:18 AM, Roberto
Ierusalimschy<roberto@inf.puc-rio.br> wrote:
>> In case it comes up for you, table.concat() is another library
>> function that is much more efficient than concatenating large numbers
>> of strings into one big string using the .. operator. And the manual
>> says this about it:
>>
>> "Given an array where all elements are strings or numbers, returns
>> table[i]..sep..table[i+1] ··· sep..table[j]. (...)"
>>
>> While it *does* return the equivalent of that, it is more efficient in
>> how it goes about it.
>
> Actually it is not :)  Remember that if you write "a..b..c..d" (as one
> single expression, as the description above) Lua does the entire
> concatenation in one single operation, allocating a buffer large enough.
>
> -- Roberto
>

Oh! Very interesting, I somehow missed that, I will have to keep it in
mind. (I think I sort of assumed it wouldn't work that way because of
the possibility that some of the elements could be a table/userdata
with a custom __concat metamethod rather than a proper string, and I
assumed that would make things too difficult.)

Thanks,

-Duncan