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

Commit 73fe46b

Browse files
author
Hendrik van Antwerpen
committed
Add methods to clear SQLiteReader instances
1 parent 62edae1 commit 73fe46b

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

stack-graphs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- New `SQLiteReader::clear` and `SQLiteReader::clear_paths` methods that make it easier to reuse instances.
13+
1014
### Changed
1115

1216
- The `Appendable` trait has been simplified. Its `Ctx` type parameter is gone, in favor of a separate trait `ToAppendable` that is used to find appendables for a handle. The type itself moved from the `cycles` to the `stitching` module.

stack-graphs/src/arena.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ impl<T> Arena<T> {
181181
}
182182
}
183183

184+
/// Clear the arena, keeping underlying allocated capacity. After this, all previous handles into
185+
/// the arena are invalid.
186+
#[inline(always)]
187+
pub(crate) fn clear(&mut self) {
188+
self.items.clear();
189+
}
190+
184191
/// Adds a new instance to this arena, returning a stable handle to it.
185192
///
186193
/// Note that we do not deduplicate instances of `T` in any way. If you add two instances that
@@ -280,6 +287,13 @@ impl<H, T> SupplementalArena<H, T> {
280287
}
281288
}
282289

290+
/// Clear the supplemantal arena, keeping underlying allocated capacity. After this,
291+
/// all previous handles into the arena are invalid.
292+
#[inline(always)]
293+
pub(crate) fn clear(&mut self) {
294+
self.items.clear();
295+
}
296+
283297
/// Creates a new, empty supplemental arena, preallocating enough space to store supplemental
284298
/// data for all of the instances that have already been allocated in a (regular) arena.
285299
pub fn with_capacity(arena: &Arena<H>) -> SupplementalArena<H, T> {

stack-graphs/src/partial.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,4 +2624,10 @@ impl PartialPaths {
26242624
partial_path_edges: Deque::new_arena(),
26252625
}
26262626
}
2627+
2628+
pub(crate) fn clear(&mut self) {
2629+
self.partial_symbol_stacks.clear();
2630+
self.partial_scope_stacks.clear();
2631+
self.partial_path_edges.clear();
2632+
}
26272633
}

stack-graphs/src/stitching.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ impl Database {
249249
}
250250
}
251251

252+
/// Clear the database. After this, all previous handles into the database are
253+
/// invalid.
254+
pub(crate) fn clear(&mut self) {
255+
self.partial_paths.clear();
256+
self.local_nodes.clear();
257+
self.symbol_stack_keys.clear();
258+
self.symbol_stack_key_cache.clear();
259+
self.paths_by_start_node.clear();
260+
self.root_paths_by_precondition.clear();
261+
}
262+
252263
/// Adds a partial path to this database. We do not deduplicate partial paths in any way; it's
253264
/// your responsibility to only add each partial path once.
254265
pub fn add_partial_path(

stack-graphs/src/storage.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,28 @@ impl SQLiteReader {
447447
})
448448
}
449449

450+
/// Clear all data that has been loaded into this reader instance.
451+
/// After this call, all existing handles from this reader are invalid.
452+
pub fn clear(&mut self) {
453+
self.loaded_graphs.clear();
454+
self.graph = StackGraph::new();
455+
456+
self.loaded_node_paths.clear();
457+
self.loaded_root_paths.clear();
458+
self.partials.clear();
459+
self.db.clear();
460+
}
461+
462+
/// Clear path data that has been loaded into this reader instance.
463+
/// After this call, all node handles remain valid, but all path data
464+
/// is invalid.
465+
pub fn clear_paths(&mut self) {
466+
self.loaded_node_paths.clear();
467+
self.loaded_root_paths.clear();
468+
self.partials.clear();
469+
self.db.clear();
470+
}
471+
450472
/// Get the file's status in the database. If a tag is provided, it must match or the file
451473
/// is reported missing.
452474
pub fn status_for_file<T: AsRef<str>>(

0 commit comments

Comments
 (0)