@@ -123,6 +123,7 @@ import Streamly.Internal.Data.Time.Clock
123 (Clock(Monotonic), asyncClock, readClock)
123 (Clock(Monotonic), asyncClock, readClock)
124import Streamly.Internal.Data.Time.Units
124import Streamly.Internal.Data.Time.Units
125 (toAbsTime, AbsTime, toRelTime64, RelTime64, addToAbsTime64)
125 (toAbsTime, AbsTime, toRelTime64, RelTime64, addToAbsTime64)
126+import Streamly.Internal.System.IO (unsafeInlineIO)
127#ifdef USE_UNFOLDS_EVERYWHERE
128#ifdef USE_UNFOLDS_EVERYWHERE
128import qualified Streamly.Internal.Data.Unfold as Unfold
129import qualified Streamly.Internal.Data.Unfold as Unfold
@@ -1143,23 +1144,23 @@ fromFoldableM = Prelude.foldr consM nil
1143-- From pointers
1144-- From pointers
1144-------------------------------------------------------------------------------
1145-------------------------------------------------------------------------------
1146−-- | Keep reading 'Storable' elements from 'Ptr' onwards.
1147+-- | Keep reading 'Storable' elements from an immutable 'Ptr' onwards.
1148-- /Unsafe:/ The caller is responsible for safe addressing.
1149-- /Unsafe:/ The caller is responsible for safe addressing.
1150-- /Pre-release/
1151-- /Pre-release/
1151{-# INLINE fromPtr #-}
1152{-# INLINE fromPtr #-}
1152−fromPtr :: forall m a. (MonadIO m, Storable a) => Ptr a -> Stream m a
1153+fromPtr :: forall m a. (Monad m, Storable a) => Ptr a -> Stream m a
1153fromPtr = Stream step
1154fromPtr = Stream step
1157 {-# INLINE_LATE step #-}
1158 {-# INLINE_LATE step #-}
1158 step _ p = do
1159 step _ p = do
1159− x <- liftIO $ peek p
1160+ let !x = unsafeInlineIO $ peek p
1160 return $ Yield x (PTR_NEXT(p, a))
1161 return $ Yield x (PTR_NEXT(p, a))
1162−-- | Take @n@ 'Storable' elements starting from 'Ptr' onwards.
1163+-- | Take @n@ 'Storable' elements starting from an immutable 'Ptr' onwards.
1164-- >>> fromPtrN n = Stream.take n . Stream.fromPtr
1165-- >>> fromPtrN n = Stream.take n . Stream.fromPtr
@@ -1167,11 +1168,11 @@ fromPtr = Stream step
1168-- /Pre-release/
1169-- /Pre-release/
1169{-# INLINE fromPtrN #-}
1170{-# INLINE fromPtrN #-}
1170−fromPtrN :: (MonadIO m, Storable a) => Int -> Ptr a -> Stream m a
1171+fromPtrN :: (Monad m, Storable a) => Int -> Ptr a -> Stream m a
1171fromPtrN n = take n . fromPtr
1172fromPtrN n = take n . fromPtr
1173−-- | Read bytes from an 'Addr#' until a 0 byte is encountered, the 0 byte is
1174+-- | Read bytes from an immutable 'Addr#' until a 0 byte is encountered, the 0
1174−-- not included in the stream.
1175+-- byte is not included in the stream.
1176-- >>> :set -XMagicHash
1177-- >>> :set -XMagicHash
1177-- >>> fromByteStr# addr = Stream.takeWhile (/= 0) $ Stream.fromPtr $ Ptr addr
1178-- >>> fromByteStr# addr = Stream.takeWhile (/= 0) $ Stream.fromPtr $ Ptr addr
@@ -1185,6 +1186,5 @@ fromPtrN n = take n . fromPtr
1185-- [1,2,3]
1186-- [1,2,3]
1187{-# INLINE fromByteStr# #-}
1188{-# INLINE fromByteStr# #-}
1188−fromByteStr# :: MonadIO m => Addr# -> Stream m Word8
1189+fromByteStr# :: Monad m => Addr# -> Stream m Word8
1190− takeWhile (/= 0) $ fromPtr $ Ptr addr
1190+fromByteStr# addr = takeWhile (/= 0) $ fromPtr $ Ptr addr