@@ -31,6 +31,9 @@ module Streamly.Internal.Data.MutByteArray.Type
3131 -- ** Access
3232 , sizeOfMutableByteArray
3333 , putSliceUnsafe
34+ , cloneSliceUnsafeAs
35+ , cloneSliceUnsafe
36+ , pinnedCloneSliceUnsafe
3437 , asPtrUnsafe
3538 ) where
3639
@@ -164,7 +167,8 @@ newBytesAs Pinned = pinnedNew
164167-------------------------------------------------------------------------------
165168
166169-- | Put a sub range of a source array into a subrange of a destination array.
167−-- This is not safe as it does not check the bounds.
170+-- This is not safe as it does not check the bounds of neither the src array
171+-- nor the destination array.
168172{-# INLINE putSliceUnsafe #-}
169173putSliceUnsafe ::
170174 MonadIO m
@@ -190,6 +194,29 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
190194 arrS# srcStartBytes# arrD# dstStartBytes# lenBytes# s#
191195 , () #)
192196
197+-- | Unsafe as it does not check whether the start offset and length supplied
198+-- are valid inside the array.
199+{-# INLINE cloneSliceUnsafeAs #-}
200+cloneSliceUnsafeAs :: MonadIO m =>
201+ PinnedState -> Int -> Int -> MutByteArray -> m MutByteArray
202+cloneSliceUnsafeAs ps srcOff srcLen src =
203+ liftIO $ do
204+ mba <- newBytesAs ps srcLen
205+ putSliceUnsafe src srcOff mba 0 srcLen
206+ return mba
207+
208+-- | @cloneSliceUnsafe offset len arr@ clones a slice of the supplied array
209+-- starting at the given offset and equal to the given length.
210+{-# INLINE cloneSliceUnsafe #-}
211+cloneSliceUnsafe :: MonadIO m => Int -> Int -> MutByteArray -> m MutByteArray
212+cloneSliceUnsafe = cloneSliceUnsafeAs Unpinned
213+
214+-- | @pinnedCloneSliceUnsafe offset len arr@
215+{-# INLINE pinnedCloneSliceUnsafe #-}
216+pinnedCloneSliceUnsafe :: MonadIO m =>
217+ Int -> Int -> MutByteArray -> m MutByteArray
218+pinnedCloneSliceUnsafe = cloneSliceUnsafeAs Pinned
219+
193220-------------------------------------------------------------------------------
194221-- Pinning & Unpinning
195222-------------------------------------------------------------------------------