mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Make find_path_inner
a query
This eliminates any remaining performance problems in the "Implement default members" assist (at least that I've found).
This commit is contained in:
parent
4677cea719
commit
6cdfd1c3cf
2 changed files with 7 additions and 4 deletions
|
@ -17,6 +17,7 @@ use crate::{
|
||||||
item_scope::ItemInNs,
|
item_scope::ItemInNs,
|
||||||
lang_item::{LangItemTarget, LangItems},
|
lang_item::{LangItemTarget, LangItems},
|
||||||
nameres::{raw::RawItems, CrateDefMap},
|
nameres::{raw::RawItems, CrateDefMap},
|
||||||
|
path::ModPath,
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
||||||
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
|
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
|
||||||
|
@ -118,6 +119,9 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
||||||
item: ItemInNs,
|
item: ItemInNs,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
) -> Arc<[(ModuleId, Name, Visibility)]>;
|
) -> Arc<[(ModuleId, Name, Visibility)]>;
|
||||||
|
|
||||||
|
#[salsa::invoke(find_path::find_path_inner_query)]
|
||||||
|
fn find_path_inner(&self, item: ItemInNs, from: ModuleId, max_len: usize) -> Option<ModPath>;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
|
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::{
|
||||||
/// *from where* you're referring to the item, hence the `from` parameter.
|
/// *from where* you're referring to the item, hence the `from` parameter.
|
||||||
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
|
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
|
||||||
let _p = profile("find_path");
|
let _p = profile("find_path");
|
||||||
find_path_inner(db, item, from, MAX_PATH_LEN)
|
db.find_path_inner(item, from, MAX_PATH_LEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_PATH_LEN: usize = 15;
|
const MAX_PATH_LEN: usize = 15;
|
||||||
|
@ -49,7 +49,7 @@ impl ModPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_path_inner(
|
pub(crate) fn find_path_inner_query(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item: ItemInNs,
|
item: ItemInNs,
|
||||||
from: ModuleId,
|
from: ModuleId,
|
||||||
|
@ -140,8 +140,7 @@ fn find_path_inner(
|
||||||
let mut best_path = None;
|
let mut best_path = None;
|
||||||
let mut best_path_len = max_len;
|
let mut best_path_len = max_len;
|
||||||
for (module_id, name) in importable_locations {
|
for (module_id, name) in importable_locations {
|
||||||
let mut path = match find_path_inner(
|
let mut path = match db.find_path_inner(
|
||||||
db,
|
|
||||||
ItemInNs::Types(ModuleDefId::ModuleId(module_id)),
|
ItemInNs::Types(ModuleDefId::ModuleId(module_id)),
|
||||||
from,
|
from,
|
||||||
best_path_len - 1,
|
best_path_len - 1,
|
||||||
|
|
Loading…
Reference in a new issue