on master help sign in
Rename fromArrayStreamK to fromChunksK
6e37f26Harendra Kumar
core/src/Streamly/Internal/Data/Array/Stream.hs+1−1
@@ -243,7 +243,7 @@ compact = packArraysChunksOf
243{-# INLINE toArray #-}
243{-# INLINE toArray #-}
244toArray :: (MonadIO m, Unbox a) => Stream m (Array a) -> m (Array a)
244toArray :: (MonadIO m, Unbox a) => Stream m (Array a) -> m (Array a)
245toArray s =
245toArray s =
246− fmap A.unsafeFreeze $ MA.fromArrayStreamRealloced (fmap A.unsafeThaw s)
246+ fmap A.unsafeFreeze $ MA.fromChunksRealloced (fmap A.unsafeThaw s)
247
247
248-------------------------------------------------------------------------------
248-------------------------------------------------------------------------------
249-- Split
249-- Split
core/src/Streamly/Internal/Data/Array/Type.hs+12−7
@@ -44,7 +44,7 @@ module Streamly.Internal.Data.Array.Type
44 , fromByteStr#
44 , fromByteStr#
45 , fromByteStr
45 , fromByteStr
46 , fromPtrN
46 , fromPtrN
47− , fromArrayStreamK
47+ , fromChunksK
48
48
49 -- ** Split
49 -- ** Split
50 , breakOn
50 , breakOn
@@ -100,6 +100,7 @@ module Streamly.Internal.Data.Array.Type
100 , bufferChunks
100 , bufferChunks
101 , flattenArrays
101 , flattenArrays
102 , flattenArraysRev
102 , flattenArraysRev
103+ , fromArrayStreamK
103 )
104 )
104where
105where
105
106
@@ -265,7 +266,7 @@ isPinned = MA.isPinned . unsafeThaw
265-- | Copy two immutable arrays into a new array. If you want to splice more
266-- | Copy two immutable arrays into a new array. If you want to splice more
266-- than two arrays then this operation would be highly inefficient because it
267-- than two arrays then this operation would be highly inefficient because it
267-- would make a copy on every splice operation, instead use the
268-- 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.
269{-# INLINE splice #-}
270{-# INLINE splice #-}
270splice :: MonadIO m => Array a -> Array a -> m (Array a)
271splice :: MonadIO m => Array a -> Array a -> m (Array a)
271splice arr1 arr2 =
272splice arr1 arr2 =
@@ -683,15 +684,19 @@ fromByteStr# addr = unsafePerformIO $ fmap unsafeFreeze (MA.fromByteStr# addr)
683fromByteStr :: Ptr Word8 -> Array Word8
684fromByteStr :: Ptr Word8 -> Array Word8
684fromByteStr (Ptr addr#) = fromByteStr# addr#
685fromByteStr (Ptr addr#) = fromByteStr# addr#
685
686
686−-- XXX implement fromArrayStream/fromArrayList instead?
687+-- XXX implement fromChunks/fromChunkList instead?
687
688
688-- | Convert an array stream to an array. Note that this requires peak memory
689-- | Convert an array stream to an array. Note that this requires peak memory
689-- that is double the size of the array stream.
690-- that is double the size of the array stream.
690--
691--
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+
691−{-# INLINE fromArrayStreamK #-}
697+{-# DEPRECATED fromArrayStreamK "Please use fromChunksK instead." #-}
692fromArrayStreamK :: (Unbox a, MonadIO m) => StreamK m (Array a) -> m (Array a)
698fromArrayStreamK :: (Unbox a, MonadIO m) => StreamK m (Array a) -> m (Array a)
693−fromArrayStreamK stream =
699+fromArrayStreamK = fromChunksK
694− fmap unsafeFreeze $ MA.fromArrayStreamK $ fmap unsafeThaw stream
695
700
696-------------------------------------------------------------------------------
701-------------------------------------------------------------------------------
697-- Instances
702-- Instances
@@ -850,7 +855,7 @@ instance Foldable Array where
850
855
851-- | This should not be used for combining many or N arrays as it would copy
856-- | This should not be used for combining many or N arrays as it would copy
852-- the two arrays everytime to a new array. For coalescing multiple arrays use
857-- the two arrays everytime to a new array. For coalescing multiple arrays use
853−-- 'fromArrayStreamK' instead.
858+-- 'fromChunksK' instead.
854instance Unbox a => Semigroup (Array a) where
859instance Unbox a => Semigroup (Array a) where
855 arr1 <> arr2 = unsafePerformIO $ splice arr1 arr2
860 arr1 <> arr2 = unsafePerformIO $ splice arr1 arr2
856
861
core/src/Streamly/Internal/Data/MutArray/Type.hs+24−12
@@ -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
83
83
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
238+ , fromArrayStreamK
238 )
239 )
239where
240where
240
241
@@ -1997,7 +1998,7 @@ writeWithAs ps elemCount =
1997--
1998--
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)
2001--
2002--
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.
2119
2120
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.
2143--
2145--
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
2153
2155
2156+-- XXX Need to compare this with fromChunks and fromChunkList and keep the
2157+-- fastest or simplest one if all are equally fast.
2158+
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.
2156--
2161--
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+
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
2161
2173
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
2167
2179
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