on master help sign in
move touch at the end of the loop
b96d735Harendra Kumar
src/Streamly/Memory/Array/Types.hs+4−5
@@ -420,7 +420,9 @@ readU = Unfold step inject
420 return $ ReadUState (ForeignPtr end contents) (Ptr start)
420 return $ ReadUState (ForeignPtr end contents) (Ptr start)
421
421
422 {-# INLINE_LATE step #-}
422 {-# INLINE_LATE step #-}
423− step (ReadUState (ForeignPtr end _) p) | p == (Ptr end) = return D.Stop
423+ step (ReadUState fp@(ForeignPtr end _) p) | p == (Ptr end) =
424+ let x = unsafeInlineIO $ touchForeignPtr fp
425+ in x `seq` return D.Stop
424 step (ReadUState fp p) = do
426 step (ReadUState fp p) = do
425 -- unsafeInlineIO allows us to run this in Identity monad for pure
427 -- unsafeInlineIO allows us to run this in Identity monad for pure
426 -- toList/foldr case which makes them much faster due to not
428 -- toList/foldr case which makes them much faster due to not
@@ -428,10 +430,7 @@ readU = Unfold step inject
428 --
430 --
429 -- This should be safe as the array contents are guaranteed to be
431 -- This should be safe as the array contents are guaranteed to be
430 -- evaluated/written to before we peek at them.
432 -- evaluated/written to before we peek at them.
431− let !x = unsafeInlineIO $ do
433+ let !x = unsafeInlineIO $ peek p
432− r <- peek p
433− touchForeignPtr fp
434− return r
435 return $ D.Yield x
434 return $ D.Yield x
436 (ReadUState fp (p `plusPtr` (sizeOf (undefined :: a))))
435 (ReadUState fp (p `plusPtr` (sizeOf (undefined :: a))))
437
436