on master help sign in
Use recursion for `Cached<R>` tracing
ca871d6Nick Fitzgerald
src/cached_set.rs+21−23
@@ -75,33 +75,31 @@ impl CachedSet {
75 // node has.
75 // node has.
76 fn trace(&self, node: &Node) -> FxHashSet<CacheId> {
76 fn trace(&self, node: &Node) -> FxHashSet<CacheId> {
77 let mut edges = FxHashSet::default();
77 let mut edges = FxHashSet::default();
78+ self.trace_recursive(&mut edges, node);
79+ edges
80+ }
78
81
79− let bump = Bump::new();
82+ fn trace_recursive(&self, edges: &mut FxHashSet<CacheId>, node: &Node) {
80− let mut stack = bumpalo::collections::Vec::with_capacity_in(64, &bump);
81− stack.push(node);
82−
83− while let Some(node) = stack.pop() {
84− match &node.kind {
83+ match &node.kind {
85− NodeKind::Text(_) => continue,
84+ NodeKind::Text(_) => return,
86− NodeKind::Cached(c) => {
85+ NodeKind::Cached(c) => {
87− debug_assert!(self.items.contains_key(&c.id));
86+ debug_assert!(self.items.contains_key(&c.id));
88− edges.insert(c.id);
87+ edges.insert(c.id);
89− edges.extend(
88+ edges.extend(
90− self.items
89+ self.items
91− .get(&c.id)
90+ .get(&c.id)
92− .expect_throw("CachedSet::trace: should have c.id in cached set")
91+ .expect_throw("CachedSet::trace: should have c.id in cached set")
93− .edges
92+ .edges
94− .iter()
93+ .iter()
95− .cloned(),
94+ .cloned(),
96− );
95+ );
97− }
96+ }
98− NodeKind::Element(el) => {
97+ NodeKind::Element(el) => {
99− stack.extend(el.children);
98+ for child in el.children {
99+ self.trace_recursive(edges, child);
100 }
100 }
101 }
101 }
102 }
102 }
103−
104− edges
105 }
103 }
106
104
107 fn next_id(&mut self) -> CacheId {
105 fn next_id(&mut self) -> CacheId {