what was done All array-like Lua tables that are created/filled by the engine, got the "n" member removed, which contained the arrays size. This is as of now in current spring master, and will be in the next release.
necessary changes Instead of reading the "n" member of tables to get their size, you have to use the # operator now. This change is backwards compatible; if you apply it to your Lua, it will also work in current release. -> do it asap! example:
Code:
- for i=1,ud.weapons.n do + for i=1,#ud.weapons do
reasoning Your Lua code will be a bit cleaner, and more portable, and in theory it would be a bit faster (unnoticeable in practice).
I came across this too. It seems to be a workaround to remove the n element from the table so pairs can be used without checking for n. It could be removed with 0.83 or you could rewrite the use of pairs to use #table because it seems stupid to use pairs on an iterable table.
Iirc jk's lua page says ipairs is slower than "for i=1, #table do". I haven't come across a table where the #table approach fails to be equivalent to ipairs.
#t is 1.0406504065041 times slower than t.n for an array of size 100 #t is 2.0826446280992 times slower than t.n for an array of size 1000 #t is 2.8423236514523 times slower than t.n for an array of size 10000 #t is 4.6935483870968 times slower than t.n for an array of size 100000 #t is 5.2921810699588 times slower than t.n for an array of size 1000000
Imo, we don't have to worry about performance, since the API usually returns small arrays.
Code:
function test(size) local iterations = 10000000 local t = {} t.n = size for i=1, t.n do t[i] = 2 end local t1 = os.clock() for i=1, iterations do local _ = #t end local t2 = os.clock() local lengthOperatorTime = t2 - t1
local t1 = os.clock() for i=1, iterations do local _ = t.n end local t2 = os.clock() local dotNTime = t2 - t1
print("#t is "..lengthOperatorTime/dotNTime.." times slower than t.n for an array of size "..size) end
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
hoijui wrote:
necessary changes Instead of reading the "n" member of tables to get their size, you have to use the # operator now. This change is backwards compatible; if you apply it to your Lua, it will also work in current release. -> do it asap!
This is as clear as fresh horseshit.
so this: arg.n becomes: arg or: arg.# or:#arg or...
How about some proper explanations. Also, was this really freaking necessary? Perhaps just one freaking release without you guys breaking lua for no damn good reason.
Users browsing this forum: No registered users and 2 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum