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
......@@ -13,7 +13,7 @@ module MA.Coalgebra.Parser
, module MA.Coalgebra.Parser.Class
) where
import Control.Monad (void)
import Control.Monad (void, forM_)
import Data.Bifunctor
import Data.Tuple
import Data.Void (Void)
......@@ -25,6 +25,7 @@ import qualified Data.Text as T
import Lens.Micro.Platform
import Text.Megaparsec hiding (State)
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.DeepSeq (NFData)
import Data.MorphismEncoding (Encoding, State)
......@@ -80,10 +81,10 @@ finalizeState :: forall f.
finalizeState state =
let
h1s = state ^. h1Map
h1Vec = V.generate (M.size h1s) $ \i ->
case M.lookup i h1s of
Nothing -> error "should not happen" -- FIXME: Handle this case better
Just x -> x
h1Vec = V.create $ do
v <- VM.unsafeNew (M.size h1s)
forM_ (M.toList h1s) $ \(i, h1) -> VM.unsafeWrite v i h1
return v
!edges = V.concat (state ^. graph)
!symTab = M.fromList (map swap (M.toList (fmap fst (state ^. symbolTable))))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment