[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: getn
- From: "Curt Carpenter" <curtc@<a href="/cgi-bin/echo.cgi?microsoft.com">...</a>>
- Date: Wed, 27 Feb 2002 11:41:04 -0800
> Lua does not have this information readily available. It only has the
size of the hash table, which is unrelated to the number of non-nil
entries in it.
Ok, sorry, I assumed it did, which looked to be the case from a casual
glance at some of the sources.
> A simple solution, which has come up in the lengthy discussion about
getn in the past, is to use a separate table to cache this info. You'd
use your tables to index this table and store n in it. --lhf
I don't see this as a good solution. It means that you have to have a
tag method to support it. Which means you can't reuse code that relies
on it, since you don't own the tag method for all tables you might
operate on. And then there's the perf issue I keep coming back to. Lua
could be much more performant by keeping a count of elements without any
extra tag method lookups, function calls, and more table lookups. Maybe
I'm in the minority, but performance is a very critical facet of the
language for me. It seems that anything which is broadly applicable and
useful, and can be done in a generic way internally in Lua much faster
than you can on top of Lua is a good thing.