procedure DiffRange(l1a, l1e, l2a, l2e: integer);
var
l1s, l2s, maxm, bp1, bp2, bsz, scan, idx, pos, cnt: integer;
begin
while true
do
begin
l1s := l1e - l1a;
l2s := l2e - l2a;
if l1s > l2s
then
maxm := l2s
else
maxm := l1s;
if maxm = 0
then
break;
bp1 := -1;
bp2 := -1;
bsz := 0;
scan := l1a;
while scan < l1e - bsz
do
begin
idx := HashToRange(Info1.LineHash[scan], Info2.Count);
repeat
pos := Info2.HashLine[idx];
if pos < l2a
then
break;
if pos + bsz <= l2e
then
begin
cnt := SameLines(scan, l1e, pos, l2e);
if cnt = bsz
then
if DistanceLess(l1a, l1e, l2a, l2e, bp1, bp2, scan, pos)
then
dec(bsz);
if cnt > bsz
then
begin
bsz := cnt;
bp1 := scan;
bp2 := pos;
end;
end;
idx := Info2.HashColl[idx];
until idx < 0;
if bsz > FHeuristic
then break;
if bsz + bsz >= maxm
then break;
inc(scan);
end;
if bsz = 0
then
break;
DiffRange(l1a, bp1, l2a, bp2);
l1a := bp1 + bsz;
l2a := bp2 + bsz;
end;
AddDiff(l1a, l1e, l2a, l2e);
end;