lua-users home
lua-l archive

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


On Tue, Dec 14, 2010 at 7:44 AM, Mark Hamburg <mark@grubmah.com> wrote:
> Credit where do (at least for beating me to posting), I see Steve Donovan also proposed modifying the core to better support a null value.

Yes, but the Devil is in the details - thanks for fleshing the idea
out.  Yes, it does have to be a specially-marked table, and only then
does HOLE get used internally.

So rawset(t,1,nil) actually removes [1], as opposed to t[1] = nil
which inserts HOLE.

Of course, such magic can't help in the case of 'accidental sparse arrays'

t[I1] = val1
t[I2] = val2
...

where I1,I2 may not cover the whole range

in which case it is wise to preallocate the array

   for i = 1,size do t[i] = nil end

(This is good practice anyway, except now nil assignment is fine...)

I'm also concerned about the performance implications - probably only
one way to find out!

steve d.