Originally Posted by Rainrider
you could take #{...} instead of the first select. Don't know if that's 'cheaper' though.
|
You could completely avoid using select by iterating over it as a table. This uses more memory but is far more efficient in terms of cpu usage. Cpu cycles are generally more valuable than memory, so it's usually a good trade-off.
Lua Code:
local func = function(...)
for _, arg in ipairs({...}) do
-- you can use pairs or ipairs if the order matters
-- i don't think there's much difference in performance
end
end
If you did #{...} like your example, you would already be creating a table and throwing it away just to get the number of variables.
There are situations where you wouldn't want to turn it into a table though, for example if you had a very large number of items and couldn't construct a table (there is a size limit) or you only wanted a range of items out of a very large list, then select might be more practical.