on master help sign in
Rename spliceWith and spliceWithDoubling
fff2704Harendra Kumar
src/Streamly/Internal/Data/Array/Foreign/Mut.hs+2−2
@@ -65,8 +65,8 @@ module Streamly.Internal.Data.Array.Foreign.Mut
65 , toList
65 , toList
66
66
67 -- * Combining
67 -- * Combining
68− , spliceWith
68+ , splice
69− , spliceWithDoubling
69+ , spliceExp
70 , spliceTwo
70 , spliceTwo
71
71
72 -- * Splitting
72 -- * Splitting
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+11−11
@@ -82,8 +82,8 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
82 , toList
82 , toList
83
83
84 -- * Combining
84 -- * Combining
85− , spliceWith
85+ , splice
86− , spliceWithDoubling
86+ , spliceExp
87 , spliceTwo
87 , spliceTwo
88
88
89 -- * Splitting
89 -- * Splitting
@@ -1103,14 +1103,14 @@ spliceTwo arr1 arr2 = do
1103-- | Splice an array into a pre-reserved mutable array. The user must ensure
1103-- | Splice an array into a pre-reserved mutable array. The user must ensure
1104-- that there is enough space in the mutable array, otherwise the splicing
1104-- that there is enough space in the mutable array, otherwise the splicing
1105-- fails.
1105-- fails.
1106−{-# INLINE spliceWith #-}
1106+{-# INLINE splice #-}
1107−spliceWith :: (MonadIO m) => Array a -> Array a -> m (Array a)
1107+splice :: (MonadIO m) => Array a -> Array a -> m (Array a)
1108−spliceWith dst@(Array _ end bound) src =
1108+splice dst@(Array _ end bound) src =
1109 liftIO $ do
1109 liftIO $ do
1110 let srcLen = byteLength src
1110 let srcLen = byteLength src
1111 if end `plusPtr` srcLen > bound
1111 if end `plusPtr` srcLen > bound
1112 then error
1112 then error
1113− "Bug: spliceWith: Not enough space in the target array"
1113+ "Bug: splice: Not enough space in the target array"
1114 else unsafeWithForeignPtr (aStart dst) $ \_ ->
1114 else unsafeWithForeignPtr (aStart dst) $ \_ ->
1115 unsafeWithForeignPtr (aStart src) $ \psrc -> do
1115 unsafeWithForeignPtr (aStart src) $ \psrc -> do
1116 let pdst = aEnd dst
1116 let pdst = aEnd dst
@@ -1119,10 +1119,10 @@ spliceWith dst@(Array _ end bound) src =
1119
1119
1120-- | Splice a new array into a preallocated mutable array, doubling the space
1120-- | Splice a new array into a preallocated mutable array, doubling the space
1121-- if there is no space in the target array.
1121-- if there is no space in the target array.
1122−{-# INLINE spliceWithDoubling #-}
1122+{-# INLINE spliceExp #-}
1123−spliceWithDoubling :: (MonadIO m, Storable a)
1123+spliceExp :: (MonadIO m, Storable a)
1124 => Array a -> Array a -> m (Array a)
1124 => 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
1126 assert (end <= bound) (return ())
1126 assert (end <= bound) (return ())
1127 let srcLen = aEnd src `minusPtr` unsafeForeignPtrToPtr (aStart src)
1127 let srcLen = aEnd src `minusPtr` unsafeForeignPtrToPtr (aStart src)
1128
1128
@@ -1134,12 +1134,12 @@ spliceWithDoubling dst@(Array start end bound) src = do
1134 newSize = max (oldSize * 2) (oldSize + srcLen)
1134 newSize = max (oldSize * 2) (oldSize + srcLen)
1135 when (newSize < oldSize + srcLen)
1135 when (newSize < oldSize + srcLen)
1136 $ error
1136 $ error
1137− $ "spliceWith: newSize is less than the total size "
1137+ $ "splice: newSize is less than the total size "
1138 ++ "of arrays being appended. Please check the "
1138 ++ "of arrays being appended. Please check the "
1139 ++ "newSize function passed."
1139 ++ "newSize function passed."
1140 liftIO $ realloc newSize dst
1140 liftIO $ realloc newSize dst
1141 else return dst
1141 else return dst
1142− spliceWith dst1 src
1142+ splice dst1 src
1143
1143
1144-------------------------------------------------------------------------------
1144-------------------------------------------------------------------------------
1145-- Splitting
1145-- Splitting
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+1−1
@@ -473,7 +473,7 @@ spliceArraysRealloced s = do
473 let idst = liftIO $ MA.newArray (bytesToElemCount (undefined :: a)
473 let idst = liftIO $ MA.newArray (bytesToElemCount (undefined :: a)
474 (mkChunkSizeKB 4))
474 (mkChunkSizeKB 4))
475
475
476− arr <- S.foldlM' MA.spliceWithDoubling idst (S.map A.unsafeThaw s)
476+ arr <- S.foldlM' MA.spliceExp idst (S.map A.unsafeThaw s)
477 liftIO $ A.unsafeFreeze <$> MA.shrinkToFit arr
477 liftIO $ A.unsafeFreeze <$> MA.shrinkToFit arr
478
478
479-- XXX This should just be "fold A.write"
479-- 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) =
114 buf' <- if MArray.byteCapacity buf < n
114 buf' <- if MArray.byteCapacity buf < n
115 then liftIO $ MArray.realloc n buf
115 then liftIO $ MArray.realloc n buf
116 else return buf
116 else return buf
117− buf'' <- MArray.spliceWith buf' arr
117+ buf'' <- MArray.splice buf' arr
118 return $ D.Skip (SpliceBuffering s buf'')
118 return $ D.Skip (SpliceBuffering s buf'')
119 D.Skip s -> return $ D.Skip (SpliceBuffering s buf)
119 D.Skip s -> return $ D.Skip (SpliceBuffering s buf)
120 D.Stop -> return $ D.Skip (SpliceYielding buf SpliceFinish)
120 D.Stop -> return $ D.Skip (SpliceYielding buf SpliceFinish)
@@ -168,7 +168,7 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
168 buf' <- if MArray.byteCapacity buf < len
168 buf' <- if MArray.byteCapacity buf < len
169 then liftIO $ MArray.realloc (max n len) buf
169 then liftIO $ MArray.realloc (max n len) buf
170 else return buf
170 else return buf
171− buf'' <- MArray.spliceWith buf' arr
171+ buf'' <- MArray.splice buf' arr
172
172
173 -- XXX this is common in both the equations of step
173 -- XXX this is common in both the equations of step
174 if len >= n
174 if len >= n