Skip to content

Commit eaa4fcb

Browse files
Less reallocations
1 parent ec731e1 commit eaa4fcb

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pub(crate) fn replace_derive_with_manual_impl(
7272
items_locator::AssocItemSearch::Exclude,
7373
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
7474
)
75-
.into_iter()
7675
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
7776
ModuleDef::Trait(trait_) => Some(trait_),
7877
_ => None,

crates/ide_completion/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ pub fn resolve_completion_edits(
161161
items_locator::AssocItemSearch::Include,
162162
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
163163
)
164-
.into_iter()
165164
.filter_map(|candidate| {
166165
current_module
167166
.find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)

crates/ide_db/src/helpers/import_assets.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ fn path_applicable_imports(
267267
AssocItemSearch::Exclude,
268268
Some(DEFAULT_QUERY_SEARCH_LIMIT),
269269
)
270-
.into_iter()
271270
.filter_map(|item| {
272271
let mod_path = mod_path(item)?;
273272
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
@@ -285,7 +284,6 @@ fn path_applicable_imports(
285284
AssocItemSearch::Include,
286285
Some(DEFAULT_QUERY_SEARCH_LIMIT),
287286
)
288-
.into_iter()
289287
.filter_map(|item| {
290288
import_for_item(
291289
sema.db,
@@ -430,7 +428,6 @@ fn trait_applicable_items(
430428
AssocItemSearch::AssocItemsOnly,
431429
Some(DEFAULT_QUERY_SEARCH_LIMIT),
432430
)
433-
.into_iter()
434431
.filter_map(|input| item_as_assoc(db, input))
435432
.filter_map(|assoc| {
436433
let assoc_item_trait = assoc.containing_trait(db)?;

crates/ide_db/src/items_locator.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::{
1515
symbol_index::{self, FileSymbol},
1616
RootDatabase,
1717
};
18-
use rustc_hash::FxHashSet;
1918

2019
/// A value to use, when uncertain which limit to pick.
2120
pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40;
@@ -32,13 +31,13 @@ pub enum AssocItemSearch {
3231
}
3332

3433
/// Searches for importable items with the given name in the crate and its dependencies.
35-
pub fn items_with_name(
36-
sema: &Semantics<'_, RootDatabase>,
34+
pub fn items_with_name<'a>(
35+
sema: &'a Semantics<'_, RootDatabase>,
3736
krate: Crate,
3837
name: NameToImport,
3938
assoc_item_search: AssocItemSearch,
4039
limit: Option<usize>,
41-
) -> FxHashSet<ItemInNs> {
40+
) -> impl Iterator<Item = ItemInNs> + 'a {
4241
let _p = profile::span("items_with_name").detail(|| {
4342
format!(
4443
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
@@ -94,13 +93,13 @@ pub fn items_with_name(
9493
find_items(sema, krate, assoc_item_search, local_query, external_query)
9594
}
9695

97-
fn find_items(
98-
sema: &Semantics<'_, RootDatabase>,
96+
fn find_items<'a>(
97+
sema: &'a Semantics<'_, RootDatabase>,
9998
krate: Crate,
10099
assoc_item_search: AssocItemSearch,
101100
local_query: symbol_index::Query,
102101
external_query: import_map::Query,
103-
) -> FxHashSet<ItemInNs> {
102+
) -> impl Iterator<Item = ItemInNs> + 'a {
104103
let _p = profile::span("find_items");
105104
let db = sema.db;
106105

@@ -115,21 +114,18 @@ fn find_items(
115114
// Query the local crate using the symbol index.
116115
let local_results = symbol_index::crate_symbols(db, krate.into(), local_query)
117116
.into_iter()
118-
.filter_map(|local_candidate| get_name_definition(sema, &local_candidate))
117+
.filter_map(move |local_candidate| get_name_definition(sema, &local_candidate))
119118
.filter_map(|name_definition_to_import| match name_definition_to_import {
120119
Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)),
121120
Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)),
122121
_ => None,
123122
});
124123

125-
external_importables
126-
.chain(local_results)
127-
.filter(move |&item| match assoc_item_search {
128-
AssocItemSearch::Include => true,
129-
AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
130-
AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
131-
})
132-
.collect()
124+
external_importables.chain(local_results).filter(move |&item| match assoc_item_search {
125+
AssocItemSearch::Include => true,
126+
AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
127+
AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
128+
})
133129
}
134130

135131
fn get_name_definition(

0 commit comments

Comments
 (0)