function fff(foo)
-- use a local variable for it
local var = foo
local something = var + 3
end
This may have a case-to-case basis, but my question focused is on efficiency (or maybe it's still negligible even for huge projects. I'll accept the argument about good programming practice. I'll also accept concerns about pass-by-value and pass-by-reference.
Last edited by sphyrth on Thu Nov 05, 2020 10:23 pm, edited 1 time in total.
"foo" is already local so there would be no difference.
In fact the second version might be very slightly slower because it allocates more stack space.
As MrFariator mentioned, tables are always references and you can never pass a table as a value.
Also, according to my understanding of how the JIT works, if that fragment gets compiled, I expect it won't make any difference in the compiled result whatsoever, as the extra assignment will be optimized out.