Skip to content

Commit

Permalink
Refactor writePrimFixed and writePrimBounded
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsmith committed Nov 24, 2013
1 parent 03858ab commit 6deab94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions Blaze/ByteString/Builder/Compat/Write.hs
Expand Up @@ -21,11 +21,9 @@ import Data.ByteString.Builder.Prim.Internal
import Blaze.ByteString.Builder.Internal.Write

writePrimFixed :: FixedPrim a -> a -> Write
writePrimFixed fe a = Write (size fe) (Poke wio)
where wio op = do
runF fe a op
return $! (op `plusPtr` size fe)
writePrimFixed fe a = exactWrite (size fe) (runF fe a)
{-# INLINE writePrimFixed #-}

writePrimBounded :: BoundedPrim a -> a -> Write
writePrimBounded be a = Write (sizeBound be) (Poke wio)
where wio = runB be a
writePrimBounded be a = boundedWrite (sizeBound be) (Poke (runB be a))
{-# INLINE writePrimBounded #-}
2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder/Internal/Write.hs
Expand Up @@ -145,7 +145,7 @@ instance Monoid Write where
{-# INLINE pokeN #-}
pokeN :: Int
-> (Ptr Word8 -> IO ()) -> Poke
pokeN size io = Poke $ \op -> io op >> return (op `plusPtr` size)
pokeN size io = Poke $ \op -> io op >> (return $! (op `plusPtr` size))


-- | @exactWrite size io@ creates a bounded write that can later be converted to
Expand Down

0 comments on commit 6deab94

Please sign in to comment.