@@ -78,8 +78,8 @@ module Streamly.Internal.Data.MutArray.Type
78 , fromPureStream
78 , fromPureStream
79 , fromByteStr#
79 , fromByteStr#
80 , fromPtrN
80 , fromPtrN
81− , fromArrayStreamK
81+ , fromChunksK
82− , fromArrayStreamRealloced
82+ , fromChunksRealloced
84 -- ** Random writes
84 -- ** Random writes
85 , putIndex
85 , putIndex
@@ -235,6 +235,7 @@ module Streamly.Internal.Data.MutArray.Type
235 , writeChunks
235 , writeChunks
236 , flattenArrays
236 , flattenArrays
237 , flattenArraysRev
237 , flattenArraysRev
@@ -1997,7 +1998,7 @@ writeWithAs ps elemCount =
1998-- >>> f n = MutArray.writeAppendWith (* 2) (MutArray.new n)
1999-- >>> f n = MutArray.writeAppendWith (* 2) (MutArray.new n)
1999-- >>> writeWith n = Fold.rmapM MutArray.rightSize (f n)
2000-- >>> writeWith n = Fold.rmapM MutArray.rightSize (f n)
2000−-- >>> writeWith n = Fold.rmapM MutArray.fromArrayStreamK (MutArray.buildChunks n)
2001+-- >>> writeWith n = Fold.rmapM MutArray.fromChunksK (MutArray.buildChunks n)
2002-- /Pre-release/
2003-- /Pre-release/
2003{-# INLINE_NORMAL writeWith #-}
2004{-# INLINE_NORMAL writeWith #-}
@@ -2117,10 +2118,11 @@ fromByteStr# addr = do
2117-- XXX Both of these implementations of splicing seem to perform equally well.
2118-- XXX Both of these implementations of splicing seem to perform equally well.
2118-- We need to perform benchmarks over a range of sizes though.
2119-- We need to perform benchmarks over a range of sizes though.
2120−{-# INLINE fromArrayStreamRealloced #-}
2121+-- | Also see 'fromChunksK'.
2122+{-# INLINE fromChunksRealloced #-}
2121−fromArrayStreamRealloced :: forall m a. (MonadIO m, Unbox a)
2123+fromChunksRealloced :: forall m a. (MonadIO m, Unbox a)
2122 => Stream m (MutArray a) -> m (MutArray a)
2124 => Stream m (MutArray a) -> m (MutArray a)
2123−fromArrayStreamRealloced s = do
2125+fromChunksRealloced s = do
2124 res <- D.uncons s
2126 res <- D.uncons s
2125 case res of
2127 case res of
2126 Just (a, strm) -> do
2128 Just (a, strm) -> do
@@ -2141,29 +2143,39 @@ arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
2141-- | Convert an array stream to an array. Note that this requires peak memory
2143-- | Convert an array stream to an array. Note that this requires peak memory
2142-- that is double the size of the array stream.
2144-- that is double the size of the array stream.
2144−{-# INLINE fromArrayStreamKAs #-}
2146+{-# INLINE fromChunkskAs #-}
2145−fromArrayStreamKAs :: (Unbox a, MonadIO m) =>
2147+fromChunkskAs :: (Unbox a, MonadIO m) =>
2146 PinnedState -> StreamK m (MutArray a) -> m (MutArray a)
2148 PinnedState -> StreamK m (MutArray a) -> m (MutArray a)
2147−fromArrayStreamKAs ps as = do
2149+fromChunkskAs ps as = do
2148 len <- arrayStreamKLength as
2150 len <- arrayStreamKLength as
2149 arr <- newAs ps len
2151 arr <- newAs ps len
2150 -- XXX is StreamK fold faster or StreamD fold?
2152 -- XXX is StreamK fold faster or StreamD fold?
2151 K.foldlM' spliceUnsafe (pure arr) as
2153 K.foldlM' spliceUnsafe (pure arr) as
2152 -- fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
2154 -- fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
2156+-- XXX Need to compare this with fromChunks and fromChunkList and keep the
2157+-- fastest or simplest one if all are equally fast.
2154-- | Convert an array stream to an array. Note that this requires peak memory
2159-- | Convert an array stream to an array. Note that this requires peak memory
2155-- that is double the size of the array stream.
2160-- that is double the size of the array stream.
2162+-- Also see 'fromChunksRealloced'.
2164+{-# INLINE fromChunksK #-}
2165+fromChunksK :: (Unbox a, MonadIO m) =>
2166+ StreamK m (MutArray a) -> m (MutArray a)
2167+fromChunksK = fromChunkskAs Unpinned
2157−{-# INLINE fromArrayStreamK #-}
2169+{-# DEPRECATED fromArrayStreamK "Please use fromChunksK instead." #-}
2158fromArrayStreamK :: (Unbox a, MonadIO m) =>
2170fromArrayStreamK :: (Unbox a, MonadIO m) =>
2159 StreamK m (MutArray a) -> m (MutArray a)
2171 StreamK m (MutArray a) -> m (MutArray a)
2160−fromArrayStreamK = fromArrayStreamKAs Unpinned
2172+fromArrayStreamK = fromChunksK
2162{-# INLINE fromStreamDAs #-}
2174{-# INLINE fromStreamDAs #-}
2163fromStreamDAs ::
2175fromStreamDAs ::
2164 (MonadIO m, Unbox a) => PinnedState -> D.Stream m a -> m (MutArray a)
2176 (MonadIO m, Unbox a) => PinnedState -> D.Stream m a -> m (MutArray a)
2165fromStreamDAs ps m =
2177fromStreamDAs ps m =
2166− arrayStreamKFromStreamDAs Unpinned m >>= fromArrayStreamKAs ps
2178+ arrayStreamKFromStreamDAs Unpinned m >>= fromChunkskAs ps
2168-- CAUTION: a very large number (millions) of arrays can degrade performance
2180-- CAUTION: a very large number (millions) of arrays can degrade performance
2169-- due to GC overhead because we need to buffer the arrays before we flatten
2181-- due to GC overhead because we need to buffer the arrays before we flatten