Skip to content

Commit feb45d0

Browse files
authored
suggestions.c: Improve efficiency of levenshtein_distance method (#91835)
1 parent 341689c commit feb45d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Python/suggestions.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ levenshtein_distance(const char *a, size_t a_size,
7878
// Instead of producing the whole traditional len(a)-by-len(b)
7979
// matrix, we can update just one row in place.
8080
// Initialize the buffer row
81+
size_t tmp = MOVE_COST;
8182
for (size_t i = 0; i < a_size; i++) {
8283
// cost from b[:0] to a[:i+1]
83-
buffer[i] = (i + 1) * MOVE_COST;
84+
buffer[i] = tmp;
85+
tmp += MOVE_COST;
8486
}
8587

8688
size_t result = 0;

0 commit comments

Comments
 (0)