lua-users home
lua-l archive

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

> Date: Sun, 24 Nov 2013 17:58:12 -0500
> From: Sean Conner <>
> Subject: Re: table library changes (was Re: in 5.3?)
>   So, aside from a performance optimization, yes, it can all be done in
> pure
> Lua.  But I also don't follow your "encourages inefficient coding'
> logic
> here.

Having the existing single element table.remove and table.insert encourages users to write code like:

t = {}
for i=1, 10000 do t[i] = i end
for i=10, 100 do table.remove(t, i) end

which is about 1000,000 table writes.

An optimised algorithm looks something like this:

t = {}
for i=1, 10000 do t[i] = i end
for i=11, 9899 do t[i] = t[91+i] end
for i=10000, 9900, -1 do t[i] = nil end

only about 10,000 table writes.

Clearly, the optimised algorithm could be written in C as a multi-value remove library function, and like any algorithm it will be a faster in C than in Lua. But I do not think it will be sufficiently faster to justify its place in a C library.

This email is free from viruses and malware because avast! Antivirus protection is active.