From 7734883342f30719f6fb0673007a0fc306f32214 Mon Sep 17 00:00:00 2001 From: harrison3000 Date: Mon, 2 May 2022 19:54:57 -0300 Subject: [PATCH] reduce the number of allocations on LevenshteinDistance --- fuzzy/levenshtein.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuzzy/levenshtein.go b/fuzzy/levenshtein.go index 237923d..4fb5838 100644 --- a/fuzzy/levenshtein.go +++ b/fuzzy/levenshtein.go @@ -10,10 +10,10 @@ package fuzzy // http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Levenshtein_distance#C func LevenshteinDistance(s, t string) int { r1, r2 := []rune(s), []rune(t) - column := make([]int, len(r1)+1) + column := make([]int, 1, 64) for y := 1; y <= len(r1); y++ { - column[y] = y + column = append(column, y) } for x := 1; x <= len(r2); x++ {