lua-users home
lua-l archive

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


On Dec 12, 2010, at 8:30 PM, Enrico Colombini wrote:

>> t[1] is quicker than #t>  0, especially if t is a long array.
> > (Not my idea, Javier Guerra pointed this out in
> > http://lua-users.org/lists/lua-l/2008-03/msg00540.html)
> 
> Interesting... I always thought #t required constant time.
> However, t[1] is not equivalent to #t if the 'array' has a hole in t[1].

Alternatively:

type( next( t ) ) == 'number'