on master help sign in
Move chunksOfRange to MutArray module
commitec11426699cda1f454ad3877b1125107c41f4223 authorHarendra Kumar <harendra@composewell.com> dateWed 27 Dec 2023, 03:55 (3 years ago) parent3bab5b7
2 files changed+13−20
core/src/Streamly/Internal/Data/Array/Stream.hs−20 core/src/Streamly/Internal/Data/MutArray/Type.hs+13
core/src/Streamly/Internal/Data/Array/Stream.hs−20
@@ -558,26 +558,6 @@ toArray :: (MonadIO m, Unbox a) => Stream m (Array a) -> m (Array a)
558558toArray = spliceArraysRealloced
559559-- spliceArrays = _spliceArraysBuffered
560560
561−-- exponentially increasing sizes of the chunks upto the max limit.
562−-- XXX this will be easier to implement with parsers/terminating folds
563−-- With this we should be able to reduce the number of chunks/allocations.
564−-- The reallocation/copy based toArray can also be implemented using this.
565−--
566−{-
567−{-# INLINE toArraysInRange #-}
568−toArraysInRange :: (MonadIO m, Unbox a)
569− => Int -> Int -> Fold m (Array a) b -> Fold m a b
570−toArraysInRange low high (Fold step initial extract) =
571−-}
572−
573−{-
574−-- | Fold the input to a pure buffered stream (List) of arrays.
575−{-# INLINE _toArraysOf #-}
576−_toArraysOf :: (MonadIO m, Unbox a)
577− => Int -> Fold m a (Stream Identity (Array a))
578−_toArraysOf n = FL.groupsOf n (A.writeNF n) FL.toStream
579−-}
580−
581561-------------------------------------------------------------------------------
582562-- Elimination - running element parsers
583563-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/MutArray/Type.hs+13
@@ -1385,6 +1385,19 @@ pinnedChunksOf :: forall m a. (MonadIO m, Unbox a)
13851385-- pinnedChunksOf n = D.foldMany (pinnedWriteN n)
13861386pinnedChunksOf = chunksOfAs Pinned
13871387
1388+-- | When we are buffering a stream of unknown size into an array we do not
1389+-- know how much space to pre-allocate. So we start with the min size and emit
1390+-- the array then keep on doubling the size every time. Thus we do not need to
1391+-- guess the optimum chunk size.
1392+--
1393+-- We can incorporate this in chunksOfAs if the additional size parameter does
1394+-- not impact perf.
1395+--
1396+{-# INLINE _chunksOfRange #-}
1397+_chunksOfRange :: -- (MonadIO m, Unbox a) =>
1398+ PinnedState -> Int -> Int -> D.Stream m a -> D.Stream m (MutArray a)
1399+_chunksOfRange _ps _low _hi = undefined
1400+
13881401-- XXX buffer to a list instead?
13891402-- | Buffer the stream into arrays in memory.
13901403{-# INLINE arrayStreamKFromStreamDAs #-}