From fe910c7bc4aac8a33fc1933d64aa260d42a3c4f1 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 26 May 2021 01:26:16 +0200 Subject: Reduce memory usage a bit --- crates/hir_def/src/item_tree.rs | 8 ++++---- crates/hir_def/src/item_tree/lower.rs | 15 ++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 508736885..c960f66d6 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -543,18 +543,18 @@ pub enum UseTreeKind { /// use path::to::Item as Renamed; /// use path::to::Trait as _; /// ``` - Single { path: ModPath, alias: Option }, + Single { path: Interned, alias: Option }, /// ```ignore /// use *; // (invalid, but can occur in nested tree) /// use path::*; /// ``` - Glob { path: Option }, + Glob { path: Option> }, /// ```ignore /// use prefix::{self, Item, ...}; /// ``` - Prefixed { prefix: Option, list: Vec }, + Prefixed { prefix: Option>, list: Box<[UseTree]> }, } #[derive(Debug, Clone, Eq, PartialEq)] @@ -811,7 +811,7 @@ impl UseTree { }, None => prefix, }; - for tree in list { + for tree in &**list { tree.expand_impl(prefix.clone(), cb); } } diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 798ab46dd..40f3428b7 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -864,7 +864,12 @@ impl UseTreeLowering<'_> { let list = use_tree_list.use_trees().filter_map(|tree| self.lower_use_tree(tree)).collect(); - Some(self.use_tree(UseTreeKind::Prefixed { prefix, list }, tree)) + Some( + self.use_tree( + UseTreeKind::Prefixed { prefix: prefix.map(Interned::new), list }, + tree, + ), + ) } else { let is_glob = tree.star_token().is_some(); let path = match tree.path() { @@ -883,15 +888,15 @@ impl UseTreeLowering<'_> { if path.is_none() { cov_mark::hit!(glob_enum_group); } - Some(self.use_tree(UseTreeKind::Glob { path }, tree)) + Some(self.use_tree(UseTreeKind::Glob { path: path.map(Interned::new) }, tree)) } // Globs can't be renamed (_, Some(_), true) | (None, None, false) => None, // `bla::{ as Name}` is invalid (None, Some(_), false) => None, - (Some(path), alias, false) => { - Some(self.use_tree(UseTreeKind::Single { path, alias }, tree)) - } + (Some(path), alias, false) => Some( + self.use_tree(UseTreeKind::Single { path: Interned::new(path), alias }, tree), + ), } } } -- cgit v1.2.3