lua-users home
lua-l archive

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


On Aug 1, 2014, at 12:08 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> 
> If there is no API function for this, then there is no call for having
> it in Lua.
> 
> What would such an API function do? Traverse the whole table and
> set every value to nil, in order to adjust the reference count. It's not
> obvious that the performance enhancement relative to
> 
> for k in pairs(tbl) do tbl[k]=nil end
> 
> is worth yet another library function in a language that can't even carry
> the baggage of cosh, sinh and tanh.
> 

Well I suspect that there are plenty of opportunities for the C code to do a far better job performance-wise (clearing out hash buckets en masse for example).

However, I’m not too sure of the use cases here. Mostly, table.clear(x) can be replaced with x = {}. The only places this will not work is if the actually table is referenced from many locations (say, upvalues), but I’m not sure that these are particularly good designs anyway. Why create an API to encourage use of anti-patterns?

—Tim