@@ -146,13 +146,13 @@ import GHC.Word
146--ipv6Header = 'runBitGet' ('block' ipv6headerblock)
146--ipv6Header = 'runBitGet' ('block' ipv6headerblock)
149−data S = S !ByteString -- Input
149+data S = S {-# UNPACK #-} !ByteString -- Input
150− !Int -- Bit offset (0-7)
150+ {-# UNPACK #-} !Int -- Bit offset (0-7)
151 deriving (Show)
151 deriving (Show)
153-- | A block that will be read with only one boundry check. Needs to know the
153-- | A block that will be read with only one boundry check. Needs to know the
154-- number of bits in advance.
154-- number of bits in advance.
155−data Block a = Block !Int (S -> a)
155+data Block a = Block Int (S -> a)
157instance Functor Block where
157instance Functor Block where
158 fmap f (Block i p) = Block i (\s -> f (p s))
158 fmap f (Block i p) = Block i (\s -> f (p s))
@@ -170,8 +170,9 @@ instance Applicative Block where
170block :: Block a -> BitGet a
170block :: Block a -> BitGet a
171block (Block i p) = do
171block (Block i p) = do
172 ensureBits i
172 ensureBits i
173− modifyState (\s -> (incS i s, p s))
173+ s <- getState
174−
174+ putState $! (incS i s)
176incS :: Int -> S -> S
177incS :: Int -> S -> S
177incS o (S bs n) =
178incS o (S bs n) =
@@ -373,9 +374,6 @@ getState = B $ \s -> return (s,s)
373putState :: S -> BitGet ()
374putState :: S -> BitGet ()
374putState s = B $ \_ -> return (s,())
375putState s = B $ \_ -> return (s,())
376−modifyState :: (S -> (S,a)) -> BitGet a
377−modifyState f = B $ \s -> return (f s)
379-- | Make sure there are at least @n@ bits.
377-- | Make sure there are at least @n@ bits.
380ensureBits :: Int -> BitGet ()
378ensureBits :: Int -> BitGet ()
381ensureBits n = do
379ensureBits n = do