[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: C API - lua_next traversal of "array" table
- From: Philipp Janda <siffiejoe@...>
- Date: Sat, 20 Aug 2016 11:33:57 +0200
Am 20.08.2016 um 10:04 schröbte Tim Hill:
On Aug 19, 2016, at 11:50 AM, Ross Berteig <Ross@CheshireEng.com> wrote:
Since you already need to iterate, then iterating until nil saves you the additional O(log n) cost from `#t`.
Yet again, #t and iterating t to the first nil rears it’s ugly head.
If `t` contains a sequence, then the first `nil` you'll encounter is
also the only `nil`, and marks the end of the sequence. So it actually
conforms to the definition of `#` (ignoring metamethods for the moment).
Additionally, it also has defined behavior (however useful it might be)
if `t` does not contain a proper sequence. It also allows you to handle
sequences that change their sizes during iteration, and it is cheap to
do in C code. So this approach seems like a reasonable option given the
current state of things.