From 6fd2aa0c9b0322b72ca6cb496210b678dfd1428a Mon Sep 17 00:00:00 2001 From: Sean Young Date: Mon, 1 Apr 2024 10:21:57 +0100 Subject: [PATCH] Paths always have lengths Signed-off-by: Sean Young --- irp/src/build_dfa.rs | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/irp/src/build_dfa.rs b/irp/src/build_dfa.rs index 1143bc05..29e16874 100644 --- a/irp/src/build_dfa.rs +++ b/irp/src/build_dfa.rs @@ -24,7 +24,7 @@ struct Path { struct DfaEdge { from: usize, flash: bool, - length: Option>, + length: Rc, } impl NFA { @@ -143,7 +143,7 @@ impl<'a> Builder<'a> { self.verts[from].edges.push(Edge { dest: to, actions }); } - fn path_length(&self, path: &[Path]) -> Option> { + fn path_length(&self, path: &[Path]) -> Rc { let mut len: Option> = None; let mut vars: HashMap<&str, Rc> = HashMap::new(); @@ -181,30 +181,23 @@ impl<'a> Builder<'a> { } } - len + len.unwrap() } - fn path_actions( - &self, - path: &[Path], - flash: bool, - length: Option>, - ) -> Vec { + fn path_actions(&self, path: &[Path], flash: bool, length: Rc) -> Vec { let mut res: Vec = Vec::new(); - if let Some(length) = length { - res.push(if flash { - Action::Flash { - length, - complete: true, - } - } else { - Action::Gap { - length, - complete: true, - } - }); - } + res.push(if flash { + Action::Flash { + length, + complete: true, + } + } else { + Action::Gap { + length, + complete: true, + } + }); for elem in path { res.extend(self.nfa.verts[elem.to].entry.iter().cloned());