on master help sign in
Move chunksOfRange to MutArray module
ec11426Harendra Kumar
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)
558toArray = spliceArraysRealloced
558toArray = spliceArraysRealloced
559-- spliceArrays = _spliceArraysBuffered
559-- spliceArrays = _spliceArraysBuffered
560
560
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−
581-------------------------------------------------------------------------------
561-------------------------------------------------------------------------------
582-- Elimination - running element parsers
562-- Elimination - running element parsers
583-------------------------------------------------------------------------------
563-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/MutArray/Type.hs+13
@@ -1385,6 +1385,19 @@ pinnedChunksOf :: forall m a. (MonadIO m, Unbox a)
1385-- pinnedChunksOf n = D.foldMany (pinnedWriteN n)
1385-- pinnedChunksOf n = D.foldMany (pinnedWriteN n)
1386pinnedChunksOf = chunksOfAs Pinned
1386pinnedChunksOf = chunksOfAs Pinned
1387
1387
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+
1388-- XXX buffer to a list instead?
1401-- XXX buffer to a list instead?
1389-- | Buffer the stream into arrays in memory.
1402-- | Buffer the stream into arrays in memory.
1390{-# INLINE arrayStreamKFromStreamDAs #-}
1403{-# INLINE arrayStreamKFromStreamDAs #-}