add some strictness

This commit is contained in:
Rhiannon Morris 2021-05-07 14:13:54 +02:00
parent 1500c62e51
commit b8412f8e52
2 changed files with 4 additions and 4 deletions

View file

@ -10,6 +10,7 @@ maintainer: rhiannon morris <rhi@rhiannon.website>
common deps common deps
default-language: Haskell2010 default-language: Haskell2010
default-extensions: default-extensions:
BangPatterns,
BlockArguments, BlockArguments,
DerivingStrategies, DerivingStrategies,
DuplicateRecordFields, DuplicateRecordFields,

View file

@ -5,7 +5,6 @@ import IPS.Types
import Data.Attoparsec.ByteString (Parser) import Data.Attoparsec.ByteString (Parser)
import qualified Data.Attoparsec.ByteString as Parse import qualified Data.Attoparsec.ByteString as Parse
import Data.Bits import Data.Bits
import Data.Bifunctor
import qualified Data.ByteString as ByteString import qualified Data.ByteString as ByteString
import Data.Functor import Data.Functor
import qualified Data.Vector.Generic as Vector import qualified Data.Vector.Generic as Vector
@ -24,7 +23,7 @@ parseBody = uncurry Vector.fromListN <$> go where
go = eof <|> chunk go = eof <|> chunk
eof = Parse.string "EOF" $> (0, []) eof = Parse.string "EOF" $> (0, [])
chunk = liftA2 cons parseChunk go chunk = liftA2 cons parseChunk go
where cons c = bimap (+ 1) (c :) where cons c (!n, cs) = (n + 1, c : cs)
parseChunk :: Parser Chunk parseChunk :: Parser Chunk
parseChunk = do parseChunk = do
@ -45,7 +44,7 @@ parseWord24 = parseWordBE 3
parseWordBE :: (Integral a, Bits a) => Word -> Parser a parseWordBE :: (Integral a, Bits a) => Word -> Parser a
parseWordBE = go 0 where parseWordBE = go 0 where
go acc 0 = pure acc go !acc 0 = pure acc
go acc i = do go !acc i = do
b <- fromIntegral <$> Parse.anyWord8 b <- fromIntegral <$> Parse.anyWord8
go ((acc `shiftL` 8) .|. b) (i - 1) go ((acc `shiftL` 8) .|. b) (i - 1)