Skip to content

Commit 2d799cf

Browse files
shrink_to_fit TokenMap's backing storage
1 parent 9daba96 commit 2d799cf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

crates/hir_expand/src/hygiene.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub struct HygieneFrame {
7676

7777
impl HygieneFrames {
7878
fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Self {
79+
// Note that this intentionally avoids the `hygiene_frame` query to avoid blowing up memory
80+
// usage. The query is only helpful for nested `HygieneFrame`s as it avoids redundant work.
7981
HygieneFrames(Arc::new(HygieneFrame::new(db, file_id)))
8082
}
8183

crates/mbe/src/syntax_bridge.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub fn syntax_node_to_token_tree(node: &SyntaxNode) -> Option<(tt::Subtree, Toke
5151
let global_offset = node.text_range().start();
5252
let mut c = Convertor::new(node, global_offset);
5353
let subtree = c.go()?;
54+
c.id_alloc.map.entries.shrink_to_fit();
5455
Some((subtree, c.id_alloc.map))
5556
}
5657

@@ -593,7 +594,8 @@ impl<'a> TtTreeSink<'a> {
593594
}
594595
}
595596

596-
fn finish(self) -> (Parse<SyntaxNode>, TokenMap) {
597+
fn finish(mut self) -> (Parse<SyntaxNode>, TokenMap) {
598+
self.token_map.entries.shrink_to_fit();
597599
(self.inner.finish(), self.token_map)
598600
}
599601
}

0 commit comments

Comments
 (0)