Skip to content

Commit a821e2c

Browse files
committed
Auto merge of #9954 - gilescope:lev_tighten, r=ehuss
nit: Allocated slightly bigger vec than needed I think this is slightly more correct as the rest of the algorithm is focusing on chars not bytes, so this is more consistent.
2 parents caf7248 + c7a79be commit a821e2c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/cargo/util/lev_distance.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::cmp;
22

33
pub fn lev_distance(me: &str, t: &str) -> usize {
4+
let t_len = t.chars().count();
45
if me.is_empty() {
5-
return t.chars().count();
6+
return t_len;
67
}
78
if t.is_empty() {
89
return me.chars().count();
910
}
1011

11-
let mut dcol = (0..=t.len()).collect::<Vec<_>>();
12+
let mut dcol = (0..=t_len).collect::<Vec<_>>();
1213
let mut t_last = 0;
1314

1415
for (i, sc) in me.chars().enumerate() {

0 commit comments

Comments
 (0)