refactor(graph): keep the ordered visit log test-only
GraphState.history was pushed to on every node visit and deep-cloned on every super-step snapshot and map fork, but its only reader is the cfg(test) current_node accessor. Gate the field, its initializer, and the push behind cfg(test) so production builds no longer carry an unbounded Vec<String> that nothing observes.
This commit is contained in:
1 file changed
+4
@@ -499,6 +499,8 @@ pub enum Reducer {
|
|||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct GraphState {
|
pub struct GraphState {
|
||||||
data: HashMap<String, Value>,
|
data: HashMap<String, Value>,
|
||||||
|
/// Ordered visit log, kept for test assertions only.
|
||||||
|
#[cfg(test)]
|
||||||
history: Vec<String>,
|
history: Vec<String>,
|
||||||
loop_counts: HashMap<String, usize>,
|
loop_counts: HashMap<String, usize>,
|
||||||
}
|
}
|
||||||
@@ -507,6 +509,7 @@ impl GraphState {
|
|||||||
pub fn new(initial: HashMap<String, Value>) -> Self {
|
pub fn new(initial: HashMap<String, Value>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: initial,
|
data: initial,
|
||||||
|
#[cfg(test)]
|
||||||
history: Vec::new(),
|
history: Vec::new(),
|
||||||
loop_counts: HashMap::new(),
|
loop_counts: HashMap::new(),
|
||||||
}
|
}
|
||||||
@@ -535,6 +538,7 @@ impl GraphState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_node(&mut self, node_id: &str) {
|
pub fn visit_node(&mut self, node_id: &str) {
|
||||||
|
#[cfg(test)]
|
||||||
self.history.push(node_id.to_string());
|
self.history.push(node_id.to_string());
|
||||||
*self.loop_counts.entry(node_id.to_string()).or_insert(0) += 1;
|
*self.loop_counts.entry(node_id.to_string()).or_insert(0) += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user