[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: ... efficiency (was Re: class implementation)
- From: Mike Pall <mikelu-0604@...>
- Date: Thu, 6 Apr 2006 00:37:36 +0200
Mark Hamburg wrote:
> 1. #... should be the same as select( '#', ... ) but should be able to avoid
> copying the values around.
This already has a syntactic meaning (not that it would be missed
much). But special casing #... lowers the language consistency.
> 2. ...[ j ] should be the same as ( select( j, ... ) ) but again bypassing
> the need to copy values around.
Well, if you are passing much more than a handful of values to a
vararg function, then you are better off with a table, anyway.
And if you are passing just a few, then why worry about
I mean how often do you ...
a. call a vararg function in the critical code path,
b. with lots of arguments (>30 or so),
c. and need to iterate over all of them one-by-one?
> Or at the very least, the Lua library needs a standard function to generate
> an iterator from a series of values so that one could write:
> for i, arg in varargs( ... ) do
> -- code goes here
This one needs to allocate and GC a heap object _and_ copy the
values around. Copying a handful of values around (even
repeatedly) may or may not be more efficient.
> (It doesn't really need to be named "varargs" since one also ought to be
> able to write things like varargs( "red", "green", "blue" ). I just wasn't
> feeling creative about a name.)
apairs() -- argument pairs.
Would be useful even for non-vararg cases. I'd like to have this
as standard given that the implementation takes only a few lines
(but it would be limited to 255 elements or needs to defer to
table or coroutine storage).