This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 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(
190190
191191 let mut dist = dist. unwrap_or_else ( || cmp:: max ( lookup. len ( ) , 3 ) / 3 ) ;
192192 let mut best = None ;
193+ // store the candidates with the same distance, only for `use_substring_score` current.
193194 let mut next_candidates = vec ! [ ] ;
194195 for c in candidates {
195196 match if use_substring_score {
@@ -200,19 +201,25 @@ fn find_best_match_for_name_impl(
200201 Some ( 0 ) => return Some ( * c) ,
201202 Some ( d) => {
202203 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+ }
204211 next_candidates. push ( * c) ;
205- best = Some ( * c) ;
206212 } else {
207213 dist = d - 1 ;
208- best = Some ( * c) ;
209214 }
215+ best = Some ( * c) ;
210216 }
211217 None => { }
212218 }
213219 }
214220
215221 if next_candidates. len ( ) > 1 {
222+ debug_assert ! ( use_substring_score) ;
216223 best = find_best_match_for_name_impl (
217224 false ,
218225 & next_candidates,
You can’t perform that action at this time.
0 commit comments