From 342419ac10ee2d692a23a34097e249e468309b2c Mon Sep 17 00:00:00 2001 From: tfs <143269404+turbofakesmile@users.noreply.github.com> Date: Tue, 28 May 2024 19:52:20 +0200 Subject: [PATCH 1/2] Update nfa.rs 1) I clean the code with throwing out clone() method, cause its basically creates a new instance and on a scale would be costly, even if it will be small amount of resources(plus its just improve performance) 2) If I we avoid cloning Rc method we can improve memory usage. --- src/nfa.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nfa.rs b/src/nfa.rs index d149a33..59a6e88 100644 --- a/src/nfa.rs +++ b/src/nfa.rs @@ -40,14 +40,14 @@ impl NFA { } } - pub fn concat(first: &mut NFA, array_of_nfa: &mut Vec) -> NFA { - let mut current_nfa = first.clone(); + pub fn concat(first: &mut NFA, array_of_nfa: &mut Vec[NFA]) -> NFA { + let mut current_nfa = first; - for nfa in array_of_nfa.iter_mut() { - current_nfa = NFA::concat_pair(&mut current_nfa, nfa); + for nfa in array_of_nfa.iter() { + *current_nfa = NFA::concat_pair(current_nfa, nfa); } - current_nfa + current_nfa.clone() } } From bbf748a014a076cd1a353ceee7442820d263e790 Mon Sep 17 00:00:00 2001 From: tfs <143269404+turbofakesmile@users.noreply.github.com> Date: Tue, 28 May 2024 20:59:57 +0200 Subject: [PATCH 2/2] Update nfa.rs --- src/nfa.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nfa.rs b/src/nfa.rs index 59a6e88..0bc0133 100644 --- a/src/nfa.rs +++ b/src/nfa.rs @@ -43,7 +43,7 @@ impl NFA { pub fn concat(first: &mut NFA, array_of_nfa: &mut Vec[NFA]) -> NFA { let mut current_nfa = first; - for nfa in array_of_nfa.iter() { + for nfa in array_of_nfa.iter_mut() { *current_nfa = NFA::concat_pair(current_nfa, nfa); } @@ -91,8 +91,8 @@ mod test { #[test] fn test_concat() { let mut first = NFA::char("a"); - let second = NFA::char("b"); - let third = NFA::char("c"); + let mut second = NFA::char("b"); + let mut third = NFA::char("c"); dbg!(first.clone()); let mut array_of_nfa = vec![second, third];