From 56a2286c3589b1b24c2ca180bf93dd54f2cb0198 Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Sun, 4 Nov 2018 01:38:25 +0000 Subject: [PATCH] osa optimisation #6 use vec! for `curr_distances` construction, as with jaro optimisation #3 --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a7a9885..6138b8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -283,7 +283,7 @@ pub fn osa_distance(a: &str, b: &str) -> usize { let mut prev_two_distances: Vec = Vec::with_capacity(b_numchars + 1); let mut prev_distances: Vec = Vec::with_capacity(b_numchars + 1); - let mut curr_distances: Vec = Vec::with_capacity(b_numchars + 1); + let mut curr_distances: Vec = vec![0; b_numchars + 1]; let mut prev_a_char = char::MAX; let mut prev_b_char = char::MAX; @@ -291,7 +291,6 @@ pub fn osa_distance(a: &str, b: &str) -> usize { for i in 0..=b_numchars { prev_two_distances.push(i); prev_distances.push(i); - curr_distances.push(0); } for (i, a_char) in a.chars().enumerate() {