From 42c24ff25f391a1e3662ce226d510aedc9d1f0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 29 Dec 2020 14:35:49 +0200 Subject: Avoid a couple of allocations --- crates/assists/src/utils/import_assets.rs | 37 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'crates/assists/src/utils') diff --git a/crates/assists/src/utils/import_assets.rs b/crates/assists/src/utils/import_assets.rs index ff5c0e78e..4ce82c1ba 100644 --- a/crates/assists/src/utils/import_assets.rs +++ b/crates/assists/src/utils/import_assets.rs @@ -179,25 +179,24 @@ impl ImportAssets { } }; - let mut res = - imports_locator::find_exact_imports(sema, current_crate, &self.get_search_query()) - .filter_map(filter) - .filter_map(|candidate| { - let item: hir::ItemInNs = candidate.either(Into::into, Into::into); - if let Some(prefix_kind) = prefixed { - self.module_with_name_to_import.find_use_path_prefixed( - db, - item, - prefix_kind, - ) - } else { - self.module_with_name_to_import.find_use_path(db, item) - } - .map(|path| (path, item)) - }) - .filter(|(use_path, _)| use_path.len() > 1) - .take(20) - .collect::>(); + let mut res = imports_locator::find_exact_imports( + sema, + current_crate, + self.get_search_query().to_string(), + ) + .filter_map(filter) + .filter_map(|candidate| { + let item: hir::ItemInNs = candidate.either(Into::into, Into::into); + if let Some(prefix_kind) = prefixed { + self.module_with_name_to_import.find_use_path_prefixed(db, item, prefix_kind) + } else { + self.module_with_name_to_import.find_use_path(db, item) + } + .map(|path| (path, item)) + }) + .filter(|(use_path, _)| use_path.len() > 1) + .take(20) + .collect::>(); res.sort_by_key(|(path, _)| path.clone()); res } -- cgit v1.2.3