Details in the implementation of the integer 'for' loop

Changed some implementation details; in particular, it is back using
an internal variable to keep the index, with the control variable
being only a copy of that internal variable. (The direct use of
the control variable demands a check of its type for each access,
which offsets the gains from the use of a single variable.)
This commit is contained in:
Roberto Ierusalimschy
2019-03-21 16:01:55 -03:00
parent f53eabeed8
commit 682054920d
2 changed files with 49 additions and 44 deletions

View File

@@ -544,6 +544,12 @@ do
a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1)
end
do -- changing the control variable
local a
a = 0; for i = 1, 10 do a = a + 1; i = "x" end; assert(a == 10)
a = 0; for i = 10.0, 1, -1 do a = a + 1; i = "x" end; assert(a == 10)
end
-- conversion
a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5)