diff options
author | JSDurand <mmemmew@gmail.com> | 2023-01-20 14:47:06 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-01-20 14:47:06 +0800 |
commit | 973c789dae479dd8383b0f7f9cfa5f167fdf3d38 (patch) | |
tree | 86a307d61eee86cef29080e59a0325caa4e099fd /chain/src/atom | |
parent | 18d7955b7d84c00467ede38baae53f4ce1fb6908 (diff) |
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.
Diffstat (limited to 'chain/src/atom')
-rw-r--r-- | chain/src/atom/default.rs | 14 |
1 files changed, 8 insertions, 6 deletions
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, (HashSet<(LabelType<TNT>, usize)>, bool)> = - HashMap::new(); + type TerminalsValue = (HashSet<(LabelType<TNT>, usize)>, bool); + + let mut terminals_map: HashMap<usize, TerminalsValue> = 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 |