Index into prefix
or path
depending on where the match was found
This fixes a couple of tests that were panicking due to an out-of-bound access.
This commit is contained in:
parent
ed57ffe5fa
commit
995b80ff26
1 changed files with 6 additions and 2 deletions
|
@ -321,14 +321,18 @@ fn score_match(
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path_len = path.len() + prefix.len();
|
let path_len = prefix.len() + path.len();
|
||||||
let mut cur_start = 0;
|
let mut cur_start = 0;
|
||||||
let mut byte_ix = 0;
|
let mut byte_ix = 0;
|
||||||
let mut char_ix = 0;
|
let mut char_ix = 0;
|
||||||
for i in 0..query.len() {
|
for i in 0..query.len() {
|
||||||
let match_char_ix = best_position_matrix[i * path_len + cur_start];
|
let match_char_ix = best_position_matrix[i * path_len + cur_start];
|
||||||
while char_ix < match_char_ix {
|
while char_ix < match_char_ix {
|
||||||
byte_ix += path[char_ix].len_utf8();
|
let ch = prefix
|
||||||
|
.get(char_ix)
|
||||||
|
.or_else(|| path.get(char_ix - prefix.len()))
|
||||||
|
.unwrap();
|
||||||
|
byte_ix += ch.len_utf8();
|
||||||
char_ix += 1;
|
char_ix += 1;
|
||||||
}
|
}
|
||||||
cur_start = match_char_ix + 1;
|
cur_start = match_char_ix + 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue