77
77
# as an optimization, check if the next line comes right after
78
78
# the previous line, because usually it does
79
79
elif stacks and stacks[k] < apos and (k == len(stacks) - 1 or
80
stacks[k + 1] > apos):
83
83
k = bisect(stacks, apos)
85
backpointers[bpos] = lasts[k-1]
85
backpointers[bpos] = lasts[k - 1]
86
86
if k < len(stacks):
124
124
oldlength = len(answer)
125
125
if alo == ahi or blo == bhi:
129
129
for apos, bpos in unique_lcs_py(a[alo:ahi], b[blo:bhi]):
130
130
# recurse between lines which are unique in each file and match
133
133
# Most of the time, you will have a sequence of similar entries
134
if last_a_pos+1 != apos or last_b_pos+1 != bpos:
135
recurse_matches_py(a, b, last_a_pos+1, last_b_pos+1,
136
apos, bpos, answer, maxrecursion - 1)
134
if last_a_pos + 1 != apos or last_b_pos + 1 != bpos:
136
a, b, last_a_pos + 1, last_b_pos + 1, apos, bpos, answer,
137
138
last_a_pos = apos
138
139
last_b_pos = bpos
139
140
answer.append((apos, bpos))
140
141
if len(answer) > oldlength:
141
142
# find matches between the last match and the end
142
recurse_matches_py(a, b, last_a_pos+1, last_b_pos+1,
143
recurse_matches_py(a, b, last_a_pos + 1, last_b_pos + 1,
143
144
ahi, bhi, answer, maxrecursion - 1)
144
145
elif a[alo] == b[blo]:
145
146
# find matching lines at the very beginning
156
157
while nahi > alo and nbhi > blo and a[nahi - 1] == b[nbhi - 1]:
159
recurse_matches_py(a, b, last_a_pos+1, last_b_pos+1,
160
recurse_matches_py(a, b, last_a_pos + 1, last_b_pos + 1,
160
161
nahi, nbhi, answer, maxrecursion - 1)
161
162
for i in range(ahi - nahi):
162
163
answer.append((nahi + i, nbhi + i))
241
242
# Matches now has individual line pairs of
242
243
# line A matches line B, at the given offsets
243
244
self.matching_blocks = _collapse_sequences(matches)
244
self.matching_blocks.append( (len(self.a), len(self.b), 0) )
245
self.matching_blocks.append((len(self.a), len(self.b), 0))
245
246
if PatienceSequenceMatcher_py._do_check_consistency:
247
248
_check_consistency(self.matching_blocks)