Skip to content

Commit c733a28

Browse files
committed
Update assignment code
Signed-off-by: Jono Yang <[email protected]>
1 parent f273246 commit c733a28

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/licensedcode/seq.pyx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ cdef CMatch find_longest_match(a, b, Py_ssize_t alo, Py_ssize_t ahi, Py_ssize_t
7171
cdef vector[Py_ssize_t] newj2len
7272

7373
besti, bestj, bestsize = alo, blo, 0
74-
a_len = <size_t>len(a)
75-
b_len = <size_t>len(b)
76-
bufsize = max(a_len, b_len) + 1
74+
bufsize = max(ahi, bhi) + 1
7775
j2len.resize(bufsize)
7876
newj2len.resize(bufsize)
7977
# find longest junk-free match
@@ -86,14 +84,17 @@ cdef CMatch find_longest_match(a, b, Py_ssize_t alo, Py_ssize_t ahi, Py_ssize_t
8684
if cura < len_good and i in matchables:
8785
# look at all instances of a[i] in b; note that because
8886
# b2j has no junk keys, the loop is skipped if a[i] is junk
89-
for j in b2j.get(a[i], nothing):
87+
for j in b2j.get(cura, nothing):
9088
# a[i] matches b[j]
9189
if j < blo:
9290
continue
9391
if j >= bhi:
9492
break
95-
k = j2len[j] + 1
96-
newj2len[j + 1] = k
93+
if <Py_ssize_t>j2len.size() <= (j - 1):
94+
k = j2len[j - 1] + 1
95+
else:
96+
k = 1
97+
newj2len[j] = k
9798
if k > bestsize:
9899
besti = i - k + 1
99100
bestj = j - k + 1

0 commit comments

Comments
 (0)