@@ -204,6 +204,10 @@ module Streamly.Internal.Data.MutArray.Type
204 , splitAt -- XXX should be able to express using getSlice
204 , splitAt -- XXX should be able to express using getSlice
205 , breakOn
205 , breakOn
207+ -- ** Cloning arrays
207 -- ** Appending arrays
211 -- ** Appending arrays
208 , spliceCopy
212 , spliceCopy
209 , spliceWith
213 , spliceWith
@@ -2085,10 +2089,37 @@ pinnedFromList xs = fromStreamDAs Pinned $ D.fromList xs
2085fromListRev :: (MonadIO m, Unbox a) => [a] -> m (MutArray a)
2089fromListRev :: (MonadIO m, Unbox a) => [a] -> m (MutArray a)
2086fromListRev xs = fromListRevN (Prelude.length xs) xs
2090fromListRev xs = fromListRevN (Prelude.length xs) xs
2092+-------------------------------------------------------------------------------
2094+-------------------------------------------------------------------------------
2096+{-# INLINE cloneAs #-}
2097+cloneAs :: MonadIO m => PinnedState -> MutArray a -> m (MutArray a)
2100+ let startSrc = arrStart src
2101+ srcLen = arrEnd src - startSrc
2103+ newArr <- newBytesAs ps srcLen
2104+ putSliceUnsafe src startSrc newArr 0 srcLen
2105+ return $ newArr {arrEnd = newArrDst}
2107+{-# INLINE clone #-}
2108+clone :: MonadIO m => MutArray a -> m (MutArray a)
2109+clone = cloneAs Unpinned
2111+{-# INLINE pinnedClone #-}
2112+pinnedClone :: MonadIO m => MutArray a -> m (MutArray a)
2113+pinnedClone = cloneAs Pinned
2088-------------------------------------------------------------------------------
2115-------------------------------------------------------------------------------
2089-- Combining
2116-- Combining
2090-------------------------------------------------------------------------------
2117-------------------------------------------------------------------------------
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.
2092-- | Put a sub range of a source array into a subrange of a destination array.
2123-- | Put a sub range of a source array into a subrange of a destination array.
2093-- This is not safe as it does not check the bounds.
2124-- This is not safe as it does not check the bounds.
2094{-# INLINE putSliceUnsafe #-}
2125{-# INLINE putSliceUnsafe #-}