Commit ad6e2a2d authored by Lennart Kolmodin's avatar Lennart Kolmodin
Browse files

Add @dcoutts's comments regarding accursedUnutterablePerformIO.

parent 37983d3e
......@@ -198,6 +198,11 @@ flush = Builder $ \ k buf@(Buffer p o u l) ->
then k buf
else let !b = Buffer p (o+u) 0 l
!bs = S.PS p o u
-- It should be safe to use accursedUnutterablePerformIO here.
-- The place in the buffer where we write is determined by the 'b'
-- value, and writes should be deterministic. The thunk should not
-- be floated out and shared since the buffer references the
-- incoming foreign ptr.
in return $! L.Chunk bs (accursedUnutterablePerformIO (k b))
{-# INLINE [0] flush #-}
......
......@@ -414,7 +414,11 @@ unsafeReadN :: Int -> (B.ByteString -> a) -> Get a
unsafeReadN !n f = C $ \inp ks -> do
ks (B.unsafeDrop n inp) $! f inp -- strict return
-- | @readNWith n f@ where @f@ must be deterministic and not have side effects.
readNWith :: Int -> (Ptr a -> IO a) -> Get a
readNWith n f = do
-- It should be safe to use accursedUnutterablePerformIO here.
-- The action must be deterministic and not have any external side effects.
-- It depends on the value of the ByteString so the value dependencies look OK.
readN n $ \s -> accursedUnutterablePerformIO $ B.unsafeUseAsCString s (f . castPtr)
{-# INLINE readNWith #-}
Markdown is supported
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