Browse Source

strings: levenshtein_distance: remove costs calculation for default array

hikari 3 years ago
parent
commit
591732f347
1 changed files with 3 additions and 4 deletions
  1. 3 4
      core/strings/strings.odin

+ 3 - 4
core/strings/strings.odin

@@ -1833,6 +1833,9 @@ levenshtein_distance :: proc(a, b: string, allocator := context.allocator) -> in
 
 
 	if n + 1 > len(LEVENSHTEIN_DEFAULT_COSTS) {
 	if n + 1 > len(LEVENSHTEIN_DEFAULT_COSTS) {
 		costs = make([]int, n + 1, allocator)
 		costs = make([]int, n + 1, allocator)
+		for k in 0..=n {
+			costs[k] = k
+		}
 	} else {
 	} else {
 		costs = LEVENSHTEIN_DEFAULT_COSTS
 		costs = LEVENSHTEIN_DEFAULT_COSTS
 	}
 	}
@@ -1841,10 +1844,6 @@ levenshtein_distance :: proc(a, b: string, allocator := context.allocator) -> in
 		delete(costs, allocator)
 		delete(costs, allocator)
 	}
 	}
 
 
-	for k in 0..=n {
-		costs[k] = k
-	}
-
 	i: int
 	i: int
 	for c1 in a {
 	for c1 in a {
 		costs[0] = i + 1
 		costs[0] = i + 1