diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-29 13:15:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-29 13:15:07 +0000 |
commit | 343029fa9e52cf4aae7f17ed6e0e6b5b0175a172 (patch) | |
tree | 004195234e0409ddc54514a2e8b737ed8e16b74e /crates/assists/src/utils/import_assets.rs | |
parent | ef1177c5b5a7ced9866025a51c10e4375e2a37fd (diff) | |
parent | 42c24ff25f391a1e3662ce226d510aedc9d1f0e4 (diff) |
Merge #7077
7077: Avoid a couple of allocations r=Veykril a=lnicola
r? @Veykril
TBH I'm not sure this is worth it, but the other `Query` was already taking a `String`.
Co-authored-by: Laurențiu Nicola <[email protected]>
Diffstat (limited to 'crates/assists/src/utils/import_assets.rs')
-rw-r--r-- | crates/assists/src/utils/import_assets.rs | 37 |
1 files changed, 18 insertions, 19 deletions
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 { | |||
179 | } | 179 | } |
180 | }; | 180 | }; |
181 | 181 | ||
182 | let mut res = | 182 | let mut res = imports_locator::find_exact_imports( |
183 | imports_locator::find_exact_imports(sema, current_crate, &self.get_search_query()) | 183 | sema, |
184 | .filter_map(filter) | 184 | current_crate, |
185 | .filter_map(|candidate| { | 185 | self.get_search_query().to_string(), |
186 | let item: hir::ItemInNs = candidate.either(Into::into, Into::into); | 186 | ) |
187 | if let Some(prefix_kind) = prefixed { | 187 | .filter_map(filter) |
188 | self.module_with_name_to_import.find_use_path_prefixed( | 188 | .filter_map(|candidate| { |
189 | db, | 189 | let item: hir::ItemInNs = candidate.either(Into::into, Into::into); |
190 | item, | 190 | if let Some(prefix_kind) = prefixed { |
191 | prefix_kind, | 191 | self.module_with_name_to_import.find_use_path_prefixed(db, item, prefix_kind) |
192 | ) | 192 | } else { |
193 | } else { | 193 | self.module_with_name_to_import.find_use_path(db, item) |
194 | self.module_with_name_to_import.find_use_path(db, item) | 194 | } |
195 | } | 195 | .map(|path| (path, item)) |
196 | .map(|path| (path, item)) | 196 | }) |
197 | }) | 197 | .filter(|(use_path, _)| use_path.len() > 1) |
198 | .filter(|(use_path, _)| use_path.len() > 1) | 198 | .take(20) |
199 | .take(20) | 199 | .collect::<Vec<_>>(); |
200 | .collect::<Vec<_>>(); | ||
201 | res.sort_by_key(|(path, _)| path.clone()); | 200 | res.sort_by_key(|(path, _)| path.clone()); |
202 | res | 201 | res |
203 | } | 202 | } |