Skip to content

Commit a1fdaa4

Browse files
committed
Refactor so that all possible matches of y in x are matched at once.
1 parent 2b26b55 commit a1fdaa4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

xtra/DIFF.LUA

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@ local function diff_u(fn1,fn2)
1515
local function li(fn,o,l)f,e=io.open(fn,"rb")if not f then return nil,e end f:seek(S,o)local g=f:read(l)f:close()return g end
1616
b1,e,b2=li(fn1,o1,l1)if not b1 then error(e)end b2,e=li(fn2,o2,l2)if not b2 then error(e)end return b1==b2 end
1717
h,w,m=#f1//ps,#f2//ps,{}
18+
local ly,n=1
1819
for x=1,h do
1920
local b={}
2021
local function inList(v)for k,p in ipairs(b)do if v==p then return k end end end
21-
for y=1,w do if cmp(x,y)then table.insert(b,y)end end
22-
if #m>0 and m[#m].x+m[#m].l==x then
23-
if inList(m[#m].y+m[#m].l) then
24-
m[#m].l=m[#m].l+1
25-
else
26-
--TODO: Know where to run the next block
27-
local n=inList(m[#m].y+m[#m].l)
28-
if n then
29-
table.insert(m,{y=b[n],x=x,l=1})
22+
for y=ly,w do if cmp(x,y)then table.insert(b,y)end end
23+
if #b>0 then
24+
if #m>0 then
25+
if m[#m].x+m[#m].l==x then
26+
n=inList(m[#m].y+m[#m].l)
27+
if n then m[#m].l=m[#m].l+1 end
28+
else
29+
--TODO: calculate how far ahead we should be from last and current x and y
30+
n=inList(m[#m].y+m[#m].l)
31+
if n then table.insert(m,{y=b[n],x=x,l=1}) end
3032
end
31-
end
32-
else
33-
if #b>0 then
34-
local n=#m>0 and inList(m[#m].y+m[#m].l) or 1
35-
table.insert(m,{y=b[n],x=x,l=1})
33+
else
34+
table.insert(m,{y=b[1],x=x,l=1})
3635
end
3736
end
3837
end

0 commit comments

Comments
 (0)