]> git.lizzy.rs Git - rust.git/commitdiff
Less reallocations
authorKirill Bulatov <mail4score@gmail.com>
Sat, 20 Mar 2021 22:17:09 +0000 (00:17 +0200)
committerKirill Bulatov <mail4score@gmail.com>
Sun, 21 Mar 2021 09:45:37 +0000 (11:45 +0200)
crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
crates/ide_completion/src/lib.rs
crates/ide_db/src/helpers/import_assets.rs
crates/ide_db/src/items_locator.rs

index 2608b56da6ff1f1b746b91e22fe59bb31ba532d5..4f0ef52ca04faf7b0aa02cb02d52588c4c4475c9 100644 (file)
@@ -72,7 +72,6 @@ pub(crate) fn replace_derive_with_manual_impl(
         items_locator::AssocItemSearch::Exclude,
         Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
     )
-    .into_iter()
     .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
         ModuleDef::Trait(trait_) => Some(trait_),
         _ => None,
index 87cddb98eeca314a3098c8607b3e5b5e108eb672..5ac1cb48d49a2ee6eed419e04000cbe03bbd37d0 100644 (file)
@@ -161,7 +161,6 @@ pub fn resolve_completion_edits(
         items_locator::AssocItemSearch::Include,
         Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
     )
-    .into_iter()
     .filter_map(|candidate| {
         current_module
             .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
index 0da7a1a9d5ae488cf27d28775cf89c2efac06020..1881c746f691e91001c13144c8c4ba19c03eb62a 100644 (file)
@@ -267,7 +267,6 @@ fn path_applicable_imports(
                 AssocItemSearch::Exclude,
                 Some(DEFAULT_QUERY_SEARCH_LIMIT),
             )
-            .into_iter()
             .filter_map(|item| {
                 let mod_path = mod_path(item)?;
                 Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
@@ -285,7 +284,6 @@ fn path_applicable_imports(
                 AssocItemSearch::Include,
                 Some(DEFAULT_QUERY_SEARCH_LIMIT),
             )
-            .into_iter()
             .filter_map(|item| {
                 import_for_item(
                     sema.db,
@@ -430,7 +428,6 @@ fn trait_applicable_items(
         AssocItemSearch::AssocItemsOnly,
         Some(DEFAULT_QUERY_SEARCH_LIMIT),
     )
-    .into_iter()
     .filter_map(|input| item_as_assoc(db, input))
     .filter_map(|assoc| {
         let assoc_item_trait = assoc.containing_trait(db)?;
index b9d5852e2b57c1e80aa665824fcecbb7574f804c..9af94b86c2dd3747d2e3a828c4303bc423d92f94 100644 (file)
@@ -15,7 +15,6 @@
     symbol_index::{self, FileSymbol},
     RootDatabase,
 };
-use rustc_hash::FxHashSet;
 
 /// A value to use, when uncertain which limit to pick.
 pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40;
@@ -32,13 +31,13 @@ pub enum AssocItemSearch {
 }
 
 /// Searches for importable items with the given name in the crate and its dependencies.
-pub fn items_with_name(
-    sema: &Semantics<'_, RootDatabase>,
+pub fn items_with_name<'a>(
+    sema: &'a Semantics<'_, RootDatabase>,
     krate: Crate,
     name: NameToImport,
     assoc_item_search: AssocItemSearch,
     limit: Option<usize>,
-) -> FxHashSet<ItemInNs> {
+) -> impl Iterator<Item = ItemInNs> + 'a {
     let _p = profile::span("items_with_name").detail(|| {
         format!(
             "Name: {} ({:?}), crate: {:?}, limit: {:?}",
@@ -94,13 +93,13 @@ pub fn items_with_name(
     find_items(sema, krate, assoc_item_search, local_query, external_query)
 }
 
-fn find_items(
-    sema: &Semantics<'_, RootDatabase>,
+fn find_items<'a>(
+    sema: &'a Semantics<'_, RootDatabase>,
     krate: Crate,
     assoc_item_search: AssocItemSearch,
     local_query: symbol_index::Query,
     external_query: import_map::Query,
-) -> FxHashSet<ItemInNs> {
+) -> impl Iterator<Item = ItemInNs> + 'a {
     let _p = profile::span("find_items");
     let db = sema.db;
 
@@ -115,21 +114,18 @@ fn find_items(
     // Query the local crate using the symbol index.
     let local_results = symbol_index::crate_symbols(db, krate.into(), local_query)
         .into_iter()
-        .filter_map(|local_candidate| get_name_definition(sema, &local_candidate))
+        .filter_map(move |local_candidate| get_name_definition(sema, &local_candidate))
         .filter_map(|name_definition_to_import| match name_definition_to_import {
             Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)),
             Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)),
             _ => None,
         });
 
-    external_importables
-        .chain(local_results)
-        .filter(move |&item| match assoc_item_search {
-            AssocItemSearch::Include => true,
-            AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
-            AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
-        })
-        .collect()
+    external_importables.chain(local_results).filter(move |&item| match assoc_item_search {
+        AssocItemSearch::Include => true,
+        AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
+        AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
+    })
 }
 
 fn get_name_definition(