From 97c5f804256d5291de0f5347d850479306c60fd7 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 28 May 2023 14:38:50 +0200 Subject: Small code optimization --- src/Data/JLD/Flattening/NodeMap.hs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src/Data/JLD') diff --git a/src/Data/JLD/Flattening/NodeMap.hs b/src/Data/JLD/Flattening/NodeMap.hs index 2e6b8e3..06af2d4 100644 --- a/src/Data/JLD/Flattening/NodeMap.hs +++ b/src/Data/JLD/Flattening/NodeMap.hs @@ -19,7 +19,6 @@ import Data.Aeson.KeyMap qualified as KM (filterWithKey, insert, lookup, member, import Data.Foldable.WithIndex (FoldableWithIndex (..), iforM_) import Data.Map.Strict qualified as M (insert, lookup) import Data.Vector qualified as V (singleton, snoc, uniq) -import Debug.Pretty.Simple (pTraceShowM) type BNMT e m = REST BNMEnv (Either (JLDError e) ()) BNMState m @@ -127,22 +126,14 @@ buildNodeMap' element = case element of | KM.member (show KeywordValue) elementObject' -> gets bnmStateList >>= \case -- 4.1. - Nothing -> - gets (bnmStateNodeMap .> N.lookup3 bnmEnvActiveGraph bnmEnvActiveSubject bnmEnvActiveProperty) >>= \case - -- 4.1.1. - Just (Array activePropertyValue) - | notElem element activePropertyValue -> - bnmModifyNodeMap - <. N.insert bnmEnvActiveGraph bnmEnvActiveSubject bnmEnvActiveProperty - <. Array - <| V.snoc activePropertyValue element - | otherwise -> pure () - -- 4.2.2 - _ -> - bnmModifyNodeMap - <. N.insert bnmEnvActiveGraph bnmEnvActiveSubject bnmEnvActiveProperty - <. Array - <| V.singleton element + Nothing -> bnmModifyNodeMap \nodeMap -> case N.lookup3 bnmEnvActiveGraph bnmEnvActiveSubject bnmEnvActiveProperty nodeMap of + -- 4.1.1. + Just (Array activePropertyValue) + | element `notElem` activePropertyValue -> + N.insert bnmEnvActiveGraph bnmEnvActiveSubject bnmEnvActiveProperty (Array <| V.snoc activePropertyValue element) nodeMap + | otherwise -> nodeMap + -- 4.2.2 + _ -> N.insert bnmEnvActiveGraph bnmEnvActiveSubject bnmEnvActiveProperty (Array <| V.singleton element) nodeMap -- 4.2. Just list -> bnmModifyList <. const <. Just <| V.snoc list element -- 5. @@ -241,15 +232,13 @@ buildNodeMap' element = case element of -- 6.10. case KM.lookup (show KeywordGraph) elementObject' of - Just graphValue -> - void <| bnmBuildNodeMap graphValue \params -> params{bnmParamsActiveGraph = id'} + Just graphValue -> void <| bnmBuildNodeMap graphValue \params -> params{bnmParamsActiveGraph = id'} -- _ -> pure () -- 6.11. case KM.lookup (show KeywordIncluded) elementObject' of - Just includedValue -> - void <| bnmBuildNodeMap includedValue id + Just includedValue -> void <| bnmBuildNodeMap includedValue id -- _ -> pure () -- cgit v1.2.3-70-g09d2