about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2021-05-26 01:26:16 +0200
committerJonas Schievink <jonasschievink@gmail.com>2021-05-26 01:26:16 +0200
commitfe910c7bc4aac8a33fc1933d64aa260d42a3c4f1 (patch)
treea5df80090790ee5c67cb54fa8a470859c008bd01
parent356dd3d909f20b5b1e1c44205d522b7b2ead0d0e (diff)
downloadrust-fe910c7bc4aac8a33fc1933d64aa260d42a3c4f1.tar.gz
rust-fe910c7bc4aac8a33fc1933d64aa260d42a3c4f1.zip
Reduce memory usage a bit
-rw-r--r--crates/hir_def/src/item_tree.rs8
-rw-r--r--crates/hir_def/src/item_tree/lower.rs15
2 files changed, 14 insertions, 9 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index 508736885b9..c960f66d67f 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<ImportAlias> },
+    Single { path: Interned<ModPath>, alias: Option<ImportAlias> },
 
     /// ```ignore
     /// use *;  // (invalid, but can occur in nested tree)
     /// use path::*;
     /// ```
-    Glob { path: Option<ModPath> },
+    Glob { path: Option<Interned<ModPath>> },
 
     /// ```ignore
     /// use prefix::{self, Item, ...};
     /// ```
-    Prefixed { prefix: Option<ModPath>, list: Vec<UseTree> },
+    Prefixed { prefix: Option<Interned<ModPath>>, 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 798ab46dd70..40f3428b7b6 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),
+                ),
             }
         }
     }