Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit fd5323e

Browse files
ggiraldezOmarTawfik
authored andcommitted
Add {save,restore}_checkpoint to PartialPaths to be able to reclaim memory
1 parent a79c671 commit fd5323e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

stack-graphs/src/arena.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ impl<T> Arena<T> {
188188
self.items.truncate(1);
189189
}
190190

191+
pub(crate) fn truncate(&mut self, new_len: usize) {
192+
self.items.truncate(new_len);
193+
}
194+
191195
/// Adds a new instance to this arena, returning a stable handle to it.
192196
///
193197
/// Note that we do not deduplicate instances of `T` in any way. If you add two instances that

stack-graphs/src/partial.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,4 +2631,27 @@ impl PartialPaths {
26312631
self.partial_scope_stacks.clear();
26322632
self.partial_path_edges.clear();
26332633
}
2634+
2635+
pub fn save_checkpoint(&self) -> PartialPathsCheckpoint {
2636+
PartialPathsCheckpoint {
2637+
partial_symbol_stacks_len: self.partial_symbol_stacks.len(),
2638+
partial_scope_stacks_len: self.partial_scope_stacks.len(),
2639+
partial_path_edges_len: self.partial_path_edges.len(),
2640+
}
2641+
}
2642+
2643+
pub fn restore_checkpoint(&mut self, checkpoint: PartialPathsCheckpoint) {
2644+
self.partial_symbol_stacks
2645+
.truncate(checkpoint.partial_symbol_stacks_len);
2646+
self.partial_scope_stacks
2647+
.truncate(checkpoint.partial_scope_stacks_len);
2648+
self.partial_path_edges
2649+
.truncate(checkpoint.partial_path_edges_len);
2650+
}
2651+
}
2652+
2653+
pub struct PartialPathsCheckpoint {
2654+
partial_symbol_stacks_len: usize,
2655+
partial_scope_stacks_len: usize,
2656+
partial_path_edges_len: usize,
26342657
}

0 commit comments

Comments
 (0)