Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add methods to clear SQLiteReader instances
  • Loading branch information
Hendrik van Antwerpen
Hendrik van Antwerpen committed Jul 4, 2023
commit 73fe46bfd71303da844c0902677e69ba67712331
4 changes: 4 additions & 0 deletions stack-graphs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- New `SQLiteReader::clear` and `SQLiteReader::clear_paths` methods that make it easier to reuse instances.

### Changed

- 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.
Expand Down
14 changes: 14 additions & 0 deletions stack-graphs/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ impl<T> Arena<T> {
}
}

/// Clear the arena, keeping underlying allocated capacity. After this, all previous handles into
/// the arena are invalid.
#[inline(always)]
pub(crate) fn clear(&mut self) {
self.items.clear();
}

/// Adds a new instance to this arena, returning a stable handle to it.
///
/// Note that we do not deduplicate instances of `T` in any way. If you add two instances that
Expand Down Expand Up @@ -280,6 +287,13 @@ impl<H, T> SupplementalArena<H, T> {
}
}

/// Clear the supplemantal arena, keeping underlying allocated capacity. After this,
/// all previous handles into the arena are invalid.
#[inline(always)]
pub(crate) fn clear(&mut self) {
self.items.clear();
}

/// Creates a new, empty supplemental arena, preallocating enough space to store supplemental
/// data for all of the instances that have already been allocated in a (regular) arena.
pub fn with_capacity(arena: &Arena<H>) -> SupplementalArena<H, T> {
Expand Down
6 changes: 6 additions & 0 deletions stack-graphs/src/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2624,4 +2624,10 @@ impl PartialPaths {
partial_path_edges: Deque::new_arena(),
}
}

pub(crate) fn clear(&mut self) {
self.partial_symbol_stacks.clear();
self.partial_scope_stacks.clear();
self.partial_path_edges.clear();
}
}
11 changes: 11 additions & 0 deletions stack-graphs/src/stitching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ impl Database {
}
}

/// Clear the database. After this, all previous handles into the database are
/// invalid.
pub(crate) fn clear(&mut self) {
self.partial_paths.clear();
self.local_nodes.clear();
self.symbol_stack_keys.clear();
self.symbol_stack_key_cache.clear();
self.paths_by_start_node.clear();
self.root_paths_by_precondition.clear();
}

/// Adds a partial path to this database. We do not deduplicate partial paths in any way; it's
/// your responsibility to only add each partial path once.
pub fn add_partial_path(
Expand Down
22 changes: 22 additions & 0 deletions stack-graphs/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,28 @@ impl SQLiteReader {
})
}

/// Clear all data that has been loaded into this reader instance.
/// After this call, all existing handles from this reader are invalid.
pub fn clear(&mut self) {
self.loaded_graphs.clear();
self.graph = StackGraph::new();

self.loaded_node_paths.clear();
self.loaded_root_paths.clear();
self.partials.clear();
self.db.clear();
}

/// Clear path data that has been loaded into this reader instance.
/// After this call, all node handles remain valid, but all path data
/// is invalid.
pub fn clear_paths(&mut self) {
self.loaded_node_paths.clear();
self.loaded_root_paths.clear();
self.partials.clear();
self.db.clear();
}

/// Get the file's status in the database. If a tag is provided, it must match or the file
/// is reported missing.
pub fn status_for_file<T: AsRef<str>>(
Expand Down