lua-users home
lua-l archive

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


Its is an intermediate good step but not enough: users are concerned by the fact that adding items to a table is too costly, causes too many calls to the allocator and stresses the garbage collector.
I'm quite sure we can improve this by changing the implementation of tables, adding some controls on how they grow, and by using a sightly better internal representation, and possibly by adding a few APIs to existing tables (but I think that most goals could be done directly in the implementation of tables themselves, because tables are criticial objects in Lua (and almost all is built on them)

Le lun. 10 déc. 2018 à 13:20, Roberto Ierusalimschy <roberto@inf.puc-rio.br> a écrit :
> For a language like Lua I think a better solution to performant string
> construction would be something like Java's StringBuffer. This is trivial to
> do in Lua because the language emphasizes making use of the C API, and
> userdata objects are first-class in terms of language treatment. The real
> issue is that the Lua ecosystem isn't a batteries included kind of
> environment.

Many people (including me) use tables in place of string buffers. To add
an item to the buffer, we simply do 't[#t + 1] = item'. The _expression_
'table.concat(t)' produces the final string.

-- Roberto