lua-users home
lua-l archive

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


Am 01.07.2016 um 09:26 schröbte steve donovan:
On Fri, Jul 1, 2016 at 9:20 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
Why does it have to be in the standard library? You can write reasonable
array implementations in Lua right now. Why does no one do it? I think for
the following reasons:

I'll add another reason - they're going  to be slower, since it needs
to call out to C and not just use VM opcodes.

Are you sure? At least some of the array implementations I can think of don't need `__index`, so read access would be as fast as with regular tables. `__len` might even be faster for larger arrays if you store the length somewhere. You do need `__newindex` if you want to have auto-resizing for your arrays, but since this could trigger a table reallocation I'm not sure how much that will actually matter ...

And I haven't even profiled VM opcodes vs. C calls yet.

Philipp