From f7e6b186e1d2f3a31b8e21d0885e13f12f12d71b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 3 Apr 2021 20:56:53 +0200 Subject: Intern `ModPath` in `Import` Minor savings only --- crates/hir_def/src/item_tree.rs | 2 +- crates/hir_def/src/item_tree/lower.rs | 2 +- crates/hir_def/src/nameres/collector.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 69a313c7e..dd80cef23 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -529,7 +529,7 @@ impl Index> for ItemTree { /// A desugared `use` import. #[derive(Debug, Clone, Eq, PartialEq)] pub struct Import { - pub path: ModPath, + pub path: Interned, pub alias: Option, pub visibility: RawVisibilityId, pub is_glob: bool, diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 5247379c5..ead7cd7a4 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -577,7 +577,7 @@ impl Ctx { &self.hygiene, |path, _use_tree, is_glob, alias| { imports.push(id(tree.imports.alloc(Import { - path, + path: Interned::new(path), alias, visibility, is_glob, diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index c8f494707..c2e445b68 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -23,6 +23,7 @@ use crate::{ attr::Attrs, db::DefDatabase, derive_macro_as_call_id, + intern::Interned, item_scope::{ImportType, PerNsGlobImports}, item_tree::{ self, FileItemTreeId, ItemTree, ItemTreeId, MacroCall, MacroDef, MacroRules, Mod, ModItem, @@ -139,7 +140,7 @@ enum ImportSource { #[derive(Clone, Debug, Eq, PartialEq)] struct Import { - path: ModPath, + path: Interned, alias: Option, visibility: RawVisibility, is_glob: bool, @@ -181,7 +182,10 @@ impl Import { let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into()); let visibility = &tree[it.visibility]; Self { - path: ModPath::from_segments(PathKind::Plain, iter::once(it.name.clone())), + path: Interned::new(ModPath::from_segments( + PathKind::Plain, + iter::once(it.name.clone()), + )), alias: it.alias.clone(), visibility: visibility.clone(), is_glob: false, -- cgit v1.2.3