@@ -214,7 +214,6 @@ module Streamly.Internal.Data.MutArray.Type
215 , spliceExp
215 , spliceExp
216 , spliceUnsafe
216 , spliceUnsafe
218 -- , putSlice
217 -- , putSlice
219 -- , appendSlice
218 -- , appendSlice
220 -- , appendSliceFrom
219 -- , appendSliceFrom
@@ -246,6 +245,7 @@ import Streamly.Internal.Data.Unbox
246 , PinnedState(..)
245 , PinnedState(..)
247 , getMutableByteArray#
246 , getMutableByteArray#
250import GHC.Base
250import GHC.Base
@@ -2099,10 +2099,9 @@ cloneAs ps src =
2099 liftIO $ do
2099 liftIO $ do
2100 let startSrc = arrStart src
2100 let startSrc = arrStart src
2101 srcLen = arrEnd src - startSrc
2101 srcLen = arrEnd src - startSrc
2103− newArr <- newBytesAs ps srcLen
2102+ newArrContents <- Unboxed.newBytesAs ps srcLen
2104− putSliceUnsafe src startSrc newArr 0 srcLen
2103+ putSliceUnsafe (arrContents src) startSrc newArrContents 0 srcLen
2105− return $ newArr {arrEnd = newArrDst}
2104+ return $ MutArray newArrContents 0 srcLen srcLen
2107{-# INLINE clone #-}
2106{-# INLINE clone #-}
2108clone :: MonadIO m => MutArray a -> m (MutArray a)
2107clone :: MonadIO m => MutArray a -> m (MutArray a)
@@ -2116,26 +2115,6 @@ pinnedClone = cloneAs Pinned
2116-- Combining
2115-- Combining
2117-------------------------------------------------------------------------------
2116-------------------------------------------------------------------------------
2119−-- XXX Change the signature of this function to
2120−-- putSliceUnsafe :: MonadIO m => MutableByteArray -> Int -> MutableByteArray -> Int -> Int -> m ()
2121−-- We don't use the relative indexes but the absolute ones. So we should MutableByteArray to remove any confusion.
2123−-- | Put a sub range of a source array into a subrange of a destination array.
2124−-- This is not safe as it does not check the bounds.
2125−{-# INLINE putSliceUnsafe #-}
2126−putSliceUnsafe :: MonadIO m => MutArray a -> Int -> MutArray a -> Int -> Int -> m ()
2127−putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
2128− assertM(lenBytes <= arrBound dst - dstStartBytes)
2129− assertM(lenBytes <= arrEnd src - srcStartBytes)
2130− let !(I# srcStartBytes#) = srcStartBytes
2131− !(I# dstStartBytes#) = dstStartBytes
2132− !(I# lenBytes#) = lenBytes
2133− let arrS# = getMutableByteArray# (arrContents src)
2134− arrD# = getMutableByteArray# (arrContents dst)
2135− IO $ \s# -> (# copyMutableByteArray#
2136− arrS# srcStartBytes# arrD# dstStartBytes# lenBytes# s#
2139-- | Copy two arrays into a newly allocated array. If the first array is pinned
2118-- | Copy two arrays into a newly allocated array. If the first array is pinned
2140-- the spliced array is also pinned.
2119-- the spliced array is also pinned.
2141{-# INLINE spliceCopy #-}
2120{-# INLINE spliceCopy #-}
@@ -2155,10 +2134,9 @@ spliceCopy arr1 arr2 = liftIO $ do
2155 then Unboxed.pinnedNewBytes newLen
2134 then Unboxed.pinnedNewBytes newLen
2156 else Unboxed.newBytes newLen
2135 else Unboxed.newBytes newLen
2157 let len = len1 + len2
2136 let len = len1 + len2
2158− newArr = MutArray newArrContents 0 len len
2159− putSliceUnsafe arr1 start1 newArr 0 len1
2137+ putSliceUnsafe (arrContents arr1) start1 newArrContents 0 len1
2160− putSliceUnsafe arr2 start2 newArr len1 len2
2138+ putSliceUnsafe (arrContents arr2) start2 newArrContents len1 len2
2161− return newArr
2139+ return $ MutArray newArrContents 0 len len
2163-- | Really really unsafe, appends the second array into the first array. If
2141-- | Really really unsafe, appends the second array into the first array. If
2164-- the first array does not have enough space it may cause silent data
2142-- the first array does not have enough space it may cause silent data
@@ -2172,7 +2150,8 @@ spliceUnsafe dst src =
2172 srcLen = arrEnd src - startSrc
2150 srcLen = arrEnd src - startSrc
2173 endDst = arrEnd dst
2151 endDst = arrEnd dst
2174 assertM(endDst + srcLen <= arrBound dst)
2152 assertM(endDst + srcLen <= arrBound dst)
2175− putSliceUnsafe src startSrc dst endDst srcLen
2154+ (arrContents src) startSrc (arrContents dst) endDst srcLen
2176 return $ dst {arrEnd = endDst + srcLen}
2155 return $ dst {arrEnd = endDst + srcLen}
2178-- | @spliceWith sizer dst src@ mutates @dst@ to append @src@. If there is no
2157-- | @spliceWith sizer dst src@ mutates @dst@ to append @src@. If there is no