Reduce memory usage a bit

This commit is contained in:
Jonas Schievink 2021-05-26 01:26:16 +02:00
parent 356dd3d909
commit fe910c7bc4
2 changed files with 14 additions and 9 deletions

View file

@ -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);
}
}

View file

@ -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),
),
}
}
}