Skip to content

Commit b45ec84

Browse files
Fewer allocations
1 parent 0415dcd commit b45ec84

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crates/completion/src/completions/unqualified_path.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
146146
.filter(|(mod_path, _)| mod_path.len() > 1)
147147
.collect::<Vec<_>>();
148148

149+
let user_input_lowercased = potential_import_name.to_lowercase();
149150
all_mod_paths.sort_by_cached_key(|(mod_path, _)| {
150-
compute_fuzzy_completion_order_key(mod_path, &potential_import_name)
151+
compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased)
151152
});
152153

153154
acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| {
@@ -160,15 +161,16 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
160161
Some(())
161162
}
162163

163-
fn compute_fuzzy_completion_order_key(proposed_mod_path: &ModPath, user_input: &str) -> usize {
164+
fn compute_fuzzy_completion_order_key(
165+
proposed_mod_path: &ModPath,
166+
user_input_lowercased: &str,
167+
) -> usize {
164168
mark::hit!(certain_fuzzy_order_test);
165169
let proposed_import_name = match proposed_mod_path.segments.last() {
166170
Some(name) => name.to_string().to_lowercase(),
167171
None => return usize::MAX,
168172
};
169-
let user_input = user_input.to_lowercase();
170-
171-
match proposed_import_name.match_indices(&user_input).next() {
173+
match proposed_import_name.match_indices(user_input_lowercased).next() {
172174
Some((first_matching_index, _)) => first_matching_index,
173175
None => usize::MAX,
174176
}

0 commit comments

Comments
 (0)