fix[parse]: Clones the result vector only once.
I removed a `force`, I noticed that `freeze` was already doing a clone.
This commit is contained in:
parent
f9fd24261a
commit
63f3b31dbb
1 changed files with 2 additions and 3 deletions
|
@ -3,7 +3,6 @@
|
||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
module Language.Brainfuck (parse, ParseFailure, render) where
|
module Language.Brainfuck (parse, ParseFailure, render) where
|
||||||
|
|
||||||
import Control.Monad ((<$!>))
|
|
||||||
import Control.Monad.ST (runST, ST)
|
import Control.Monad.ST (runST, ST)
|
||||||
|
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
|
@ -48,7 +47,7 @@ parse text = runST $ do
|
||||||
parseBlock :: Text -> MVector s Instruction -> Int -> ST s (Either ParseFailure (Vector Instruction, Text))
|
parseBlock :: Text -> MVector s Instruction -> Int -> ST s (Either ParseFailure (Vector Instruction, Text))
|
||||||
parseBlock Text.Empty instructions index = do
|
parseBlock Text.Empty instructions index = do
|
||||||
let populatedSlice = MutableVector.take index instructions
|
let populatedSlice = MutableVector.take index instructions
|
||||||
frozen <- Vector.force <$!> Vector.freeze populatedSlice
|
frozen <- Vector.freeze populatedSlice
|
||||||
pure . Right $ (frozen, Text.empty)
|
pure . Right $ (frozen, Text.empty)
|
||||||
parseBlock t@(c Text.:< cs) instructions index = let
|
parseBlock t@(c Text.:< cs) instructions index = let
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ parse text = runST $ do
|
||||||
'.' -> recognizeInstruction PutByte cs
|
'.' -> recognizeInstruction PutByte cs
|
||||||
']' -> do
|
']' -> do
|
||||||
let populatedSlice = MutableVector.take index instructions
|
let populatedSlice = MutableVector.take index instructions
|
||||||
frozen <- Vector.force <$!> Vector.freeze populatedSlice
|
frozen <- Vector.freeze populatedSlice
|
||||||
pure $ Right (frozen, t)
|
pure $ Right (frozen, t)
|
||||||
'[' -> do
|
'[' -> do
|
||||||
innerVector <- MutableVector.new (Text.length cs)
|
innerVector <- MutableVector.new (Text.length cs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue