on master help sign in
Rename fromArrayStreamK to fromChunksK

For consistency with other names.

commit6e37f26442a45ef0ee0c370a2603ae3271806ba1 authorHarendra Kumar <harendra@composewell.com> dateSat 30 Dec 2023, 07:07 (3 years ago) parentff40cf0
3 files changed+37−20
core/src/Streamly/Internal/Data/Array/Stream.hs+1−1 core/src/Streamly/Internal/Data/Array/Type.hs+12−7 core/src/Streamly/Internal/Data/MutArray/Type.hs+24−12
core/src/Streamly/Internal/Data/Array/Stream.hs+1−1
@@ -243,7 +243,7 @@ compact = packArraysChunksOf
243243{-# INLINE toArray #-}
244244toArray :: (MonadIO m, Unbox a) => Stream m (Array a) -> m (Array a)
245245toArray s =
246− fmap A.unsafeFreeze $ MA.fromArrayStreamRealloced (fmap A.unsafeThaw s)
246+ fmap A.unsafeFreeze $ MA.fromChunksRealloced (fmap A.unsafeThaw s)
247247
248248-------------------------------------------------------------------------------
249249-- Split
core/src/Streamly/Internal/Data/Array/Type.hs+12−7
@@ -44,7 +44,7 @@ module Streamly.Internal.Data.Array.Type
4444 , fromByteStr#
4545 , fromByteStr
4646 , fromPtrN
47− , fromArrayStreamK
47+ , fromChunksK
4848
4949 -- ** Split
5050 , breakOn
@@ -100,6 +100,7 @@ module Streamly.Internal.Data.Array.Type
100100 , bufferChunks
101101 , flattenArrays
102102 , flattenArraysRev
103+ , fromArrayStreamK
103104 )
104105where
105106
@@ -265,7 +266,7 @@ isPinned = MA.isPinned . unsafeThaw
265266-- | Copy two immutable arrays into a new array. If you want to splice more
266267-- than two arrays then this operation would be highly inefficient because it
267268-- would make a copy on every splice operation, instead use the
268−-- 'fromArrayStreamK' operation to combine n immutable arrays.
269+-- 'fromChunksK' operation to combine n immutable arrays.
269270{-# INLINE splice #-}
270271splice :: MonadIO m => Array a -> Array a -> m (Array a)
271272splice arr1 arr2 =
@@ -683,15 +684,19 @@ fromByteStr# addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromByteStr# addr)
683684fromByteStr :: Ptr Word8 -> Array Word8
684685fromByteStr (Ptr addr#) = fromByteStr# addr#
685686
686−-- XXX implement fromArrayStream/fromArrayList instead?
687+-- XXX implement fromChunks/fromChunkList instead?
687688
688689-- | Convert an array stream to an array. Note that this requires peak memory
689690-- that is double the size of the array stream.
690691--
691−{-# INLINE fromArrayStreamK #-}
692+{-# INLINE fromChunksK #-}
693+fromChunksK :: (Unbox a, MonadIO m) => StreamK m (Array a) -> m (Array a)
694+fromChunksK stream =
695+ fmap unsafeFreeze $ MA.fromChunksK $ fmap unsafeThaw stream
696+
697+{-# DEPRECATED fromArrayStreamK "Please use fromChunksK instead." #-}
692698fromArrayStreamK :: (Unbox a, MonadIO m) => StreamK m (Array a) -> m (Array a)
693−fromArrayStreamK stream =
694− fmap unsafeFreeze $ MA.fromArrayStreamK $ fmap unsafeThaw stream
699+fromArrayStreamK = fromChunksK
695700
696701-------------------------------------------------------------------------------
697702-- Instances
@@ -850,7 +855,7 @@ instance Foldable Array where
850855
851856-- | This should not be used for combining many or N arrays as it would copy
852857-- the two arrays everytime to a new array. For coalescing multiple arrays use
853−-- 'fromArrayStreamK' instead.
858+-- 'fromChunksK' instead.
854859instance Unbox a => Semigroup (Array a) where
855860 arr1 <> arr2 = unsafePerformIO $ splice arr1 arr2
856861
core/src/Streamly/Internal/Data/MutArray/Type.hs+24−12
@@ -78,8 +78,8 @@ module Streamly.Internal.Data.MutArray.Type
7878 , fromPureStream
7979 , fromByteStr#
8080 , fromPtrN
81− , fromArrayStreamK
82− , fromArrayStreamRealloced
81+ , fromChunksK
82+ , fromChunksRealloced
8383
8484 -- ** Random writes
8585 , putIndex
@@ -235,6 +235,7 @@ module Streamly.Internal.Data.MutArray.Type
235235 , writeChunks
236236 , flattenArrays
237237 , flattenArraysRev
238+ , fromArrayStreamK
238239 )
239240where
240241
@@ -1997,7 +1998,7 @@ writeWithAs ps elemCount =
19971998--
19981999-- >>> f n = MutArray.writeAppendWith (* 2) (MutArray.new n)
19992000-- >>> 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)
20012002--
20022003-- /Pre-release/
20032004{-# INLINE_NORMAL writeWith #-}
@@ -2117,10 +2118,11 @@ fromByteStr# addr = do
21172118-- XXX Both of these implementations of splicing seem to perform equally well.
21182119-- We need to perform benchmarks over a range of sizes though.
21192120
2120−{-# INLINE fromArrayStreamRealloced #-}
2121−fromArrayStreamRealloced :: forall m a. (MonadIO m, Unbox a)
2121+-- | Also see 'fromChunksK'.
2122+{-# INLINE fromChunksRealloced #-}
2123+fromChunksRealloced :: forall m a. (MonadIO m, Unbox a)
21222124 => Stream m (MutArray a) -> m (MutArray a)
2123−fromArrayStreamRealloced s = do
2125+fromChunksRealloced s = do
21242126 res <- D.uncons s
21252127 case res of
21262128 Just (a, strm) -> do
@@ -2141,29 +2143,39 @@ arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
21412143-- | Convert an array stream to an array. Note that this requires peak memory
21422144-- that is double the size of the array stream.
21432145--
2144−{-# INLINE fromArrayStreamKAs #-}
2145−fromArrayStreamKAs :: (Unbox a, MonadIO m) =>
2146+{-# INLINE fromChunkskAs #-}
2147+fromChunkskAs :: (Unbox a, MonadIO m) =>
21462148 PinnedState -> StreamK m (MutArray a) -> m (MutArray a)
2147−fromArrayStreamKAs ps as = do
2149+fromChunkskAs ps as = do
21482150 len <- arrayStreamKLength as
21492151 arr <- newAs ps len
21502152 -- XXX is StreamK fold faster or StreamD fold?
21512153 K.foldlM' spliceUnsafe (pure arr) as
21522154 -- fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
21532155
2156+-- XXX Need to compare this with fromChunks and fromChunkList and keep the
2157+-- fastest or simplest one if all are equally fast.
2158+
21542159-- | Convert an array stream to an array. Note that this requires peak memory
21552160-- that is double the size of the array stream.
21562161--
2157−{-# INLINE fromArrayStreamK #-}
2162+-- Also see 'fromChunksRealloced'.
2163+--
2164+{-# INLINE fromChunksK #-}
2165+fromChunksK :: (Unbox a, MonadIO m) =>
2166+ StreamK m (MutArray a) -> m (MutArray a)
2167+fromChunksK = fromChunkskAs Unpinned
2168+
2169+{-# DEPRECATED fromArrayStreamK "Please use fromChunksK instead." #-}
21582170fromArrayStreamK :: (Unbox a, MonadIO m) =>
21592171 StreamK m (MutArray a) -> m (MutArray a)
2160−fromArrayStreamK = fromArrayStreamKAs Unpinned
2172+fromArrayStreamK = fromChunksK
21612173
21622174{-# INLINE fromStreamDAs #-}
21632175fromStreamDAs ::
21642176 (MonadIO m, Unbox a) => PinnedState -> D.Stream m a -> m (MutArray a)
21652177fromStreamDAs ps m =
2166− arrayStreamKFromStreamDAs Unpinned m >>= fromArrayStreamKAs ps
2178+ arrayStreamKFromStreamDAs Unpinned m >>= fromChunkskAs ps
21672179
21682180-- CAUTION: a very large number (millions) of arrays can degrade performance
21692181-- due to GC overhead because we need to buffer the arrays before we flatten