mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Less reallocations
This commit is contained in:
parent
ec731e19df
commit
eaa4fcbbde
4 changed files with 12 additions and 21 deletions
|
@ -72,7 +72,6 @@ pub(crate) fn replace_derive_with_manual_impl(
|
||||||
items_locator::AssocItemSearch::Exclude,
|
items_locator::AssocItemSearch::Exclude,
|
||||||
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
|
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
|
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
|
||||||
ModuleDef::Trait(trait_) => Some(trait_),
|
ModuleDef::Trait(trait_) => Some(trait_),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -161,7 +161,6 @@ pub fn resolve_completion_edits(
|
||||||
items_locator::AssocItemSearch::Include,
|
items_locator::AssocItemSearch::Include,
|
||||||
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
|
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|candidate| {
|
.filter_map(|candidate| {
|
||||||
current_module
|
current_module
|
||||||
.find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
|
.find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
|
||||||
|
|
|
@ -267,7 +267,6 @@ fn path_applicable_imports(
|
||||||
AssocItemSearch::Exclude,
|
AssocItemSearch::Exclude,
|
||||||
Some(DEFAULT_QUERY_SEARCH_LIMIT),
|
Some(DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|item| {
|
.filter_map(|item| {
|
||||||
let mod_path = mod_path(item)?;
|
let mod_path = mod_path(item)?;
|
||||||
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
|
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
|
||||||
|
@ -285,7 +284,6 @@ fn path_applicable_imports(
|
||||||
AssocItemSearch::Include,
|
AssocItemSearch::Include,
|
||||||
Some(DEFAULT_QUERY_SEARCH_LIMIT),
|
Some(DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|item| {
|
.filter_map(|item| {
|
||||||
import_for_item(
|
import_for_item(
|
||||||
sema.db,
|
sema.db,
|
||||||
|
@ -430,7 +428,6 @@ fn trait_applicable_items(
|
||||||
AssocItemSearch::AssocItemsOnly,
|
AssocItemSearch::AssocItemsOnly,
|
||||||
Some(DEFAULT_QUERY_SEARCH_LIMIT),
|
Some(DEFAULT_QUERY_SEARCH_LIMIT),
|
||||||
)
|
)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|input| item_as_assoc(db, input))
|
.filter_map(|input| item_as_assoc(db, input))
|
||||||
.filter_map(|assoc| {
|
.filter_map(|assoc| {
|
||||||
let assoc_item_trait = assoc.containing_trait(db)?;
|
let assoc_item_trait = assoc.containing_trait(db)?;
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::{
|
||||||
symbol_index::{self, FileSymbol},
|
symbol_index::{self, FileSymbol},
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
|
||||||
|
|
||||||
/// A value to use, when uncertain which limit to pick.
|
/// A value to use, when uncertain which limit to pick.
|
||||||
pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40;
|
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.
|
/// Searches for importable items with the given name in the crate and its dependencies.
|
||||||
pub fn items_with_name(
|
pub fn items_with_name<'a>(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &'a Semantics<'_, RootDatabase>,
|
||||||
krate: Crate,
|
krate: Crate,
|
||||||
name: NameToImport,
|
name: NameToImport,
|
||||||
assoc_item_search: AssocItemSearch,
|
assoc_item_search: AssocItemSearch,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> FxHashSet<ItemInNs> {
|
) -> impl Iterator<Item = ItemInNs> + 'a {
|
||||||
let _p = profile::span("items_with_name").detail(|| {
|
let _p = profile::span("items_with_name").detail(|| {
|
||||||
format!(
|
format!(
|
||||||
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
|
"Name: {} ({:?}), crate: {:?}, limit: {:?}",
|
||||||
|
@ -94,13 +93,13 @@ pub fn items_with_name(
|
||||||
find_items(sema, krate, assoc_item_search, local_query, external_query)
|
find_items(sema, krate, assoc_item_search, local_query, external_query)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_items(
|
fn find_items<'a>(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &'a Semantics<'_, RootDatabase>,
|
||||||
krate: Crate,
|
krate: Crate,
|
||||||
assoc_item_search: AssocItemSearch,
|
assoc_item_search: AssocItemSearch,
|
||||||
local_query: symbol_index::Query,
|
local_query: symbol_index::Query,
|
||||||
external_query: import_map::Query,
|
external_query: import_map::Query,
|
||||||
) -> FxHashSet<ItemInNs> {
|
) -> impl Iterator<Item = ItemInNs> + 'a {
|
||||||
let _p = profile::span("find_items");
|
let _p = profile::span("find_items");
|
||||||
let db = sema.db;
|
let db = sema.db;
|
||||||
|
|
||||||
|
@ -115,21 +114,18 @@ fn find_items(
|
||||||
// Query the local crate using the symbol index.
|
// Query the local crate using the symbol index.
|
||||||
let local_results = symbol_index::crate_symbols(db, krate.into(), local_query)
|
let local_results = symbol_index::crate_symbols(db, krate.into(), local_query)
|
||||||
.into_iter()
|
.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 {
|
.filter_map(|name_definition_to_import| match name_definition_to_import {
|
||||||
Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)),
|
Definition::ModuleDef(module_def) => Some(ItemInNs::from(module_def)),
|
||||||
Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)),
|
Definition::Macro(macro_def) => Some(ItemInNs::from(macro_def)),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
|
|
||||||
external_importables
|
external_importables.chain(local_results).filter(move |&item| match assoc_item_search {
|
||||||
.chain(local_results)
|
AssocItemSearch::Include => true,
|
||||||
.filter(move |&item| match assoc_item_search {
|
AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
|
||||||
AssocItemSearch::Include => true,
|
AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
|
||||||
AssocItemSearch::Exclude => !is_assoc_item(item, sema.db),
|
})
|
||||||
AssocItemSearch::AssocItemsOnly => is_assoc_item(item, sema.db),
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name_definition(
|
fn get_name_definition(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue