On 14/04/12 00:19, Gabriel Wicke wrote:
I am no Lua expert, but would guess that the usual collect-in-list-and--finally-join method can avoid the performance penalty in Lua too.
Yes, it works. With short strings, the memory overhead of the table elements can become excessive, so it makes sense to concatenate the strings in batches of say 1000. I imagine we would have an object-based interface, like:
local buf = mw.StringBuffer:new() for i = 1,n do buf:add('blah') end return buf:toString()
It may also be possible to use metamethods (which are similar to C++ operator overloading) to make a StringBuffer object behave like a plain string in certain contexts.
-- Tim Starling