From 973c789dae479dd8383b0f7f9cfa5f167fdf3d38 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 20 Jan 2023 14:47:06 +0800 Subject: minor refactoring It seems the performance is indeed linear for a simple grammar. This is such a historical moment, for me, that I think it deserves a separate commit, haha. --- chain/src/atom/default.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'chain/src/atom') diff --git a/chain/src/atom/default.rs b/chain/src/atom/default.rs index 0dc24c3..14b7a9f 100644 --- a/chain/src/atom/default.rs +++ b/chain/src/atom/default.rs @@ -404,8 +404,9 @@ impl DefaultAtom { .map(|(label, target_iter)| (*label, target_iter)) .collect(); - let mut terminals_map: HashMap, usize)>, bool)> = - HashMap::new(); + type TerminalsValue = (HashSet<(LabelType, usize)>, bool); + + let mut terminals_map: HashMap = HashMap::new(); for (label, children_iter) in children.into_iter() { if let Some(TNT::Ter(t)) = *label.get_value() { @@ -422,10 +423,11 @@ impl DefaultAtom { let mut accepting = false; for child in children_iter { - accepting = accepting - || *accepting_vec.get(child).ok_or_else(|| { - GrammarError::IndexOutOfBounds(child, accepting_vec.len()) - })?; + accepting = + accepting + || *accepting_vec.get(child).ok_or( + GrammarError::IndexOutOfBounds(child, accepting_vec.len()), + )?; if nt == 3 && nfa.degree(child).map_err(index_out_of_bounds_conversion)? == 0 -- cgit v1.2.3-18-g5258