From a19c6088f08f8dcf0c90f1c832c337ed59d90944 Mon Sep 17 00:00:00 2001 From: Dan Gieschen Knutson Date: Sun, 28 Oct 2018 22:26:44 -0500 Subject: [PATCH] use iterative rather than recursive method for following aliases (#573) * use iterative rather than recursive method for following aliases * this avoids consuming stack via plain recursive calls --- lib/codegen/src/write.rs | 10 +++++++--- lib/entity/src/map.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/codegen/src/write.rs b/lib/codegen/src/write.rs index 24b8499f39..d790efa920 100644 --- a/lib/codegen/src/write.rs +++ b/lib/codegen/src/write.rs @@ -283,10 +283,14 @@ fn write_value_aliases( target: Value, indent: usize, ) -> fmt::Result { - for &a in &aliases[target] { - writeln!(w, "{1:0$}{2} -> {3}", indent, "", a, target)?; - write_value_aliases(w, aliases, a, indent)?; + let mut todo_stack = vec![target]; + while let Some(target) = todo_stack.pop() { + for &a in &aliases[target] { + writeln!(w, "{1:0$}{2} -> {3}", indent, "", a, target)?; + todo_stack.push(a); + } } + Ok(()) } diff --git a/lib/entity/src/map.rs b/lib/entity/src/map.rs index 87a478e570..df8ac115a2 100644 --- a/lib/entity/src/map.rs +++ b/lib/entity/src/map.rs @@ -84,12 +84,12 @@ where Keys::with_len(self.elems.len()) } - /// Iterate over all the keys in this map. + /// Iterate over all the values in this map. pub fn values(&self) -> slice::Iter { self.elems.iter() } - /// Iterate over all the keys in this map, mutable edition. + /// Iterate over all the values in this map, mutable edition. pub fn values_mut(&mut self) -> slice::IterMut { self.elems.iter_mut() }