summaryrefslogtreecommitdiffstats
path: root/Python/suggestions.c
diff options
context:
space:
mode:
authorPieter Eendebak <pieter.eendebak@gmail.com>2022-05-02 17:09:35 (GMT)
committerGitHub <noreply@github.com>2022-05-02 17:09:35 (GMT)
commitfeb45d0ae98f3030b2b07089bc0eb066b69f5625 (patch)
tree0e2b19633a0c3245e98d541d3cd9ede9ce8fbb4e /Python/suggestions.c
parent341689cb85c4ee4f58dc9f0f96ecc94ded8fd9d4 (diff)
downloadcpython-feb45d0ae98f3030b2b07089bc0eb066b69f5625.zip
cpython-feb45d0ae98f3030b2b07089bc0eb066b69f5625.tar.gz
cpython-feb45d0ae98f3030b2b07089bc0eb066b69f5625.tar.bz2
suggestions.c: Improve efficiency of levenshtein_distance method (#91835)
Diffstat (limited to 'Python/suggestions.c')
-rw-r--r--Python/suggestions.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Python/suggestions.c b/Python/suggestions.c
index d9e69fa..b84acaa 100644
--- a/Python/suggestions.c
+++ b/Python/suggestions.c
@@ -78,9 +78,11 @@ levenshtein_distance(const char *a, size_t a_size,
// Instead of producing the whole traditional len(a)-by-len(b)
// matrix, we can update just one row in place.
// Initialize the buffer row
+ size_t tmp = MOVE_COST;
for (size_t i = 0; i < a_size; i++) {
// cost from b[:0] to a[:i+1]
- buffer[i] = (i + 1) * MOVE_COST;
+ buffer[i] = tmp;
+ tmp += MOVE_COST;
}
size_t result = 0;