on master help sign in
Rename spliceWith and spliceWithDoubling

To simply splice and spliceExp (exponential growth).

commitfff2704282a8b2f24cc3b2052efc7b4b0cf151a9 authorHarendra Kumar <harendra@composewell.com> dateSun 10 Oct 2021, 19:53 (5 years ago) parentb5b5d9b
4 files changed+16−16
src/Streamly/Internal/Data/Array/Foreign/Mut.hs+2−2 src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+11−11 src/Streamly/Internal/Data/Array/Stream/Foreign.hs+1−1 src/Streamly/Internal/Data/Array/Stream/Mut/Foreign.hs+2−2
src/Streamly/Internal/Data/Array/Foreign/Mut.hs+2−2
@@ -65,8 +65,8 @@ module Streamly.Internal.Data.Array.Foreign.Mut
6565 , toList
6666
6767 -- * Combining
68− , spliceWith
69− , spliceWithDoubling
68+ , splice
69+ , spliceExp
7070 , spliceTwo
7171
7272 -- * Splitting
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+11−11
@@ -82,8 +82,8 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
8282 , toList
8383
8484 -- * Combining
85− , spliceWith
86− , spliceWithDoubling
85+ , splice
86+ , spliceExp
8787 , spliceTwo
8888
8989 -- * Splitting
@@ -1103,14 +1103,14 @@ spliceTwo arr1 arr2 = do
11031103-- | Splice an array into a pre-reserved mutable array. The user must ensure
11041104-- that there is enough space in the mutable array, otherwise the splicing
11051105-- fails.
1106−{-# INLINE spliceWith #-}
1107−spliceWith :: (MonadIO m) => Array a -> Array a -> m (Array a)
1108−spliceWith dst@(Array _ end bound) src =
1106+{-# INLINE splice #-}
1107+splice :: (MonadIO m) => Array a -> Array a -> m (Array a)
1108+splice dst@(Array _ end bound) src =
11091109 liftIO $ do
11101110 let srcLen = byteLength src
11111111 if end `plusPtr` srcLen > bound
11121112 then error
1113− "Bug: spliceWith: Not enough space in the target array"
1113+ "Bug: splice: Not enough space in the target array"
11141114 else unsafeWithForeignPtr (aStart dst) $ \_ ->
11151115 unsafeWithForeignPtr (aStart src) $ \psrc -> do
11161116 let pdst = aEnd dst
@@ -1119,10 +1119,10 @@ spliceWith dst@(Array _ end bound) src =
11191119
11201120-- | Splice a new array into a preallocated mutable array, doubling the space
11211121-- if there is no space in the target array.
1122−{-# INLINE spliceWithDoubling #-}
1123−spliceWithDoubling :: (MonadIO m, Storable a)
1122+{-# INLINE spliceExp #-}
1123+spliceExp :: (MonadIO m, Storable a)
11241124 => Array a -> Array a -> m (Array a)
1125−spliceWithDoubling dst@(Array start end bound) src = do
1125+spliceExp dst@(Array start end bound) src = do
11261126 assert (end <= bound) (return ())
11271127 let srcLen = aEnd src `minusPtr` unsafeForeignPtrToPtr (aStart src)
11281128
@@ -1134,12 +1134,12 @@ spliceWithDoubling dst@(Array start end bound) src = do
11341134 newSize = max (oldSize * 2) (oldSize + srcLen)
11351135 when (newSize < oldSize + srcLen)
11361136 $ error
1137− $ "spliceWith: newSize is less than the total size "
1137+ $ "splice: newSize is less than the total size "
11381138 ++ "of arrays being appended. Please check the "
11391139 ++ "newSize function passed."
11401140 liftIO $ realloc newSize dst
11411141 else return dst
1142− spliceWith dst1 src
1142+ splice dst1 src
11431143
11441144-------------------------------------------------------------------------------
11451145-- Splitting
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+1−1
@@ -473,7 +473,7 @@ spliceArraysRealloced s = do
473473 let idst = liftIO $ MA.newArray (bytesToElemCount (undefined :: a)
474474 (mkChunkSizeKB 4))
475475
476− arr <- S.foldlM' MA.spliceWithDoubling idst (S.map A.unsafeThaw s)
476+ arr <- S.foldlM' MA.spliceExp idst (S.map A.unsafeThaw s)
477477 liftIO $ A.unsafeFreeze <$> MA.shrinkToFit arr
478478
479479-- XXX This should just be "fold A.write"
src/Streamly/Internal/Data/Array/Stream/Mut/Foreign.hs+2−2
@@ -114,7 +114,7 @@ packArraysChunksOf n (D.Stream step state) =
114114 buf' <- if MArray.byteCapacity buf < n
115115 then liftIO $ MArray.realloc n buf
116116 else return buf
117− buf'' <- MArray.spliceWith buf' arr
117+ buf'' <- MArray.splice buf' arr
118118 return $ D.Skip (SpliceBuffering s buf'')
119119 D.Skip s -> return $ D.Skip (SpliceBuffering s buf)
120120 D.Stop -> return $ D.Skip (SpliceYielding buf SpliceFinish)
@@ -168,7 +168,7 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
168168 buf' <- if MArray.byteCapacity buf < len
169169 then liftIO $ MArray.realloc (max n len) buf
170170 else return buf
171− buf'' <- MArray.spliceWith buf' arr
171+ buf'' <- MArray.splice buf' arr
172172
173173 -- XXX this is common in both the equations of step
174174 if len >= n