Skip to content
Snippets Groups Projects
Commit 814f7644 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Speed up MorphismEncoding creation from parser state

By not looking up every State individually in the HashMap of H1s, we
can gain a little more performance.
parent df4241d5
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ module MA.Coalgebra.Parser ...@@ -13,7 +13,7 @@ module MA.Coalgebra.Parser
, module MA.Coalgebra.Parser.Class , module MA.Coalgebra.Parser.Class
) where ) where
import Control.Monad (void) import Control.Monad (void, forM_)
import Data.Bifunctor import Data.Bifunctor
import Data.Tuple import Data.Tuple
import Data.Void (Void) import Data.Void (Void)
...@@ -25,6 +25,7 @@ import qualified Data.Text as T ...@@ -25,6 +25,7 @@ import qualified Data.Text as T
import Lens.Micro.Platform import Lens.Micro.Platform
import Text.Megaparsec hiding (State) import Text.Megaparsec hiding (State)
import qualified Data.Vector as V import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.DeepSeq (NFData) import Control.DeepSeq (NFData)
import Data.MorphismEncoding (Encoding, State) import Data.MorphismEncoding (Encoding, State)
...@@ -80,10 +81,10 @@ finalizeState :: forall f. ...@@ -80,10 +81,10 @@ finalizeState :: forall f.
finalizeState state = finalizeState state =
let let
h1s = state ^. h1Map h1s = state ^. h1Map
h1Vec = V.generate (M.size h1s) $ \i -> h1Vec = V.create $ do
case M.lookup i h1s of v <- VM.unsafeNew (M.size h1s)
Nothing -> error "should not happen" -- FIXME: Handle this case better forM_ (M.toList h1s) $ \(i, h1) -> VM.unsafeWrite v i h1
Just x -> x return v
!edges = V.concat (state ^. graph) !edges = V.concat (state ^. graph)
!symTab = M.fromList (map swap (M.toList (fmap fst (state ^. symbolTable)))) !symTab = M.fromList (map swap (M.toList (fmap fst (state ^. symbolTable))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment