File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ fn find_best_match_for_name_impl(
190
190
191
191
let mut dist = dist. unwrap_or_else ( || cmp:: max ( lookup. len ( ) , 3 ) / 3 ) ;
192
192
let mut best = None ;
193
+ // store the candidates with the same distance, only for `use_substring_score` current.
193
194
let mut next_candidates = vec ! [ ] ;
194
195
for c in candidates {
195
196
match if use_substring_score {
@@ -200,19 +201,25 @@ fn find_best_match_for_name_impl(
200
201
Some ( 0 ) => return Some ( * c) ,
201
202
Some ( d) => {
202
203
if use_substring_score {
203
- dist = d;
204
+ if d < dist {
205
+ dist = d;
206
+ next_candidates. clear ( ) ;
207
+ } else {
208
+ // `d == dist` here, we need to store the candidates with the same distance
209
+ // so we won't decrease the distance in the next loop.
210
+ }
204
211
next_candidates. push ( * c) ;
205
- best = Some ( * c) ;
206
212
} else {
207
213
dist = d - 1 ;
208
- best = Some ( * c) ;
209
214
}
215
+ best = Some ( * c) ;
210
216
}
211
217
None => { }
212
218
}
213
219
}
214
220
215
221
if next_candidates. len ( ) > 1 {
222
+ debug_assert ! ( use_substring_score) ;
216
223
best = find_best_match_for_name_impl (
217
224
false ,
218
225
& next_candidates,
You can’t perform that action at this time.
0 commit comments