lua-users home
lua-l archive

[luarocks] lub.join is slow and probably unnecessary

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


I use the 'xml' luarock which depends on the 'lub' rock.
I like it very much, but found that 'xml.dump' becomes very
slow when the XML string is very long.
I traced the reason to its use of the function 'lub.join'. This
function concatenates a list by repeatedly concatenating
the next element to the partial result, an algorithm that takes
O(n²) time, where n is the length of the final result.
Applications (such as 'xml') that do not need __concat
metamethods do not need that algorithm.
 require"lub".join = table.concat
solves all the speed problems.
-- Dirk

AltStyle によって変換されたページ (->オリジナル) /