aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-12-19 18:42:16 +0000
committerKirill Bulatov <[email protected]>2020-12-19 18:42:16 +0000
commitb45ec84739eced0d93d9ccdaa06b546a5a567dea (patch)
tree43ed5fc2718053516cfb6e4d70b66d29e4c87205
parent0415dcd8324f1acf726315fdaba919c11ab7a462 (diff)
Fewer allocations
-rw-r--r--crates/completion/src/completions/unqualified_path.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index 0fbcf4f8c..099ffb4d4 100644
--- a/crates/completion/src/completions/unqualified_path.rs
+++ b/crates/completion/src/completions/unqualified_path.rs
@@ -146,8 +146,9 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
146 .filter(|(mod_path, _)| mod_path.len() > 1) 146 .filter(|(mod_path, _)| mod_path.len() > 1)
147 .collect::<Vec<_>>(); 147 .collect::<Vec<_>>();
148 148
149 let user_input_lowercased = potential_import_name.to_lowercase();
149 all_mod_paths.sort_by_cached_key(|(mod_path, _)| { 150 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)
151 }); 152 });
152 153
153 acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { 154 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<()
160 Some(()) 161 Some(())
161} 162}
162 163
163fn compute_fuzzy_completion_order_key(proposed_mod_path: &ModPath, user_input: &str) -> usize { 164fn compute_fuzzy_completion_order_key(
165 proposed_mod_path: &ModPath,
166 user_input_lowercased: &str,
167) -> usize {
164 mark::hit!(certain_fuzzy_order_test); 168 mark::hit!(certain_fuzzy_order_test);
165 let proposed_import_name = match proposed_mod_path.segments.last() { 169 let proposed_import_name = match proposed_mod_path.segments.last() {
166 Some(name) => name.to_string().to_lowercase(), 170 Some(name) => name.to_string().to_lowercase(),
167 None => return usize::MAX, 171 None => return usize::MAX,
168 }; 172 };
169 let user_input = user_input.to_lowercase(); 173 match proposed_import_name.match_indices(user_input_lowercased).next() {
170
171 match proposed_import_name.match_indices(&user_input).next() {
172 Some((first_matching_index, _)) => first_matching_index, 174 Some((first_matching_index, _)) => first_matching_index,
173 None => usize::MAX, 175 None => usize::MAX,
174 } 176 }