Skip to content

Commit fe910c7

Browse files
Reduce memory usage a bit
1 parent 356dd3d commit fe910c7

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

crates/hir_def/src/item_tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,18 +543,18 @@ pub enum UseTreeKind {
543543
/// use path::to::Item as Renamed;
544544
/// use path::to::Trait as _;
545545
/// ```
546-
Single { path: ModPath, alias: Option<ImportAlias> },
546+
Single { path: Interned<ModPath>, alias: Option<ImportAlias> },
547547

548548
/// ```ignore
549549
/// use *; // (invalid, but can occur in nested tree)
550550
/// use path::*;
551551
/// ```
552-
Glob { path: Option<ModPath> },
552+
Glob { path: Option<Interned<ModPath>> },
553553

554554
/// ```ignore
555555
/// use prefix::{self, Item, ...};
556556
/// ```
557-
Prefixed { prefix: Option<ModPath>, list: Vec<UseTree> },
557+
Prefixed { prefix: Option<Interned<ModPath>>, list: Box<[UseTree]> },
558558
}
559559

560560
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -811,7 +811,7 @@ impl UseTree {
811811
},
812812
None => prefix,
813813
};
814-
for tree in list {
814+
for tree in &**list {
815815
tree.expand_impl(prefix.clone(), cb);
816816
}
817817
}

crates/hir_def/src/item_tree/lower.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,12 @@ impl UseTreeLowering<'_> {
864864
let list =
865865
use_tree_list.use_trees().filter_map(|tree| self.lower_use_tree(tree)).collect();
866866

867-
Some(self.use_tree(UseTreeKind::Prefixed { prefix, list }, tree))
867+
Some(
868+
self.use_tree(
869+
UseTreeKind::Prefixed { prefix: prefix.map(Interned::new), list },
870+
tree,
871+
),
872+
)
868873
} else {
869874
let is_glob = tree.star_token().is_some();
870875
let path = match tree.path() {
@@ -883,15 +888,15 @@ impl UseTreeLowering<'_> {
883888
if path.is_none() {
884889
cov_mark::hit!(glob_enum_group);
885890
}
886-
Some(self.use_tree(UseTreeKind::Glob { path }, tree))
891+
Some(self.use_tree(UseTreeKind::Glob { path: path.map(Interned::new) }, tree))
887892
}
888893
// Globs can't be renamed
889894
(_, Some(_), true) | (None, None, false) => None,
890895
// `bla::{ as Name}` is invalid
891896
(None, Some(_), false) => None,
892-
(Some(path), alias, false) => {
893-
Some(self.use_tree(UseTreeKind::Single { path, alias }, tree))
894-
}
897+
(Some(path), alias, false) => Some(
898+
self.use_tree(UseTreeKind::Single { path: Interned::new(path), alias }, tree),
899+
),
895900
}
896901
}
897902
}

0 commit comments

Comments
 (0)