[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: need help: some features of Lua don't fit well together
- From: Coda Highland <chighland@...>
- Date: Tue, 14 Apr 2015 15:25:48 -0700
On Tue, Apr 14, 2015 at 3:19 PM, Aapo Talvensaari
<aapo.talvensaari@gmail.com> wrote:
> On 15 April 2015 at 00:24, Javier Guerra Giraldez <javier@guerrag.com>
> wrote:
>> that "array part" is an optimization that holds _some_ values, but
>> it's not guaranteed that all integer keys are stored there.
>
> Ah, okay, thanks for correcting me. Talking about optimizations, wouldn't
> say adding sizeints optimize functions like ipairs (with maybe slight
> overhead on adding new elements, and a little bit more memory consumption).
> And adding something like sizekeys you could then easily check if sizeints
> == sizekeys -> "is array", making it an optimization for Konstantin's
> problem (with possibility for internal optimizations as well). Or maybe this
> isn't too common, and can be worked on a Lua side as well (say having
> metatable that collects just that).
>
>
> Regards
> Aapo
It actually wouldn't optimize ipairs particularly well considering
that ipairs stops at the first nil, and it would add overhead to every
single write to the table -- not really a good tradeoff.
But you can do it with a metatable on the Lua side if this is a use
case that's important to you. Having such an easy, well-supported
mechanism for that is further reason not to do it in the core.
/s/ Adam