@@ -773,6 +773,7 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do
773773-- down to multiples of array size. If the new size is more than
774774-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
775775--
776+-- If the original array is pinned, the newly allocated array is also pinned.
776777{-# INLINABLE realloc #-}
777778realloc :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (MutArray a)
778779realloc bytes arr = liftIO $ reallocExplicit (SIZE_OF(a)) bytes arr
@@ -2094,7 +2095,8 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
20942095 arrS# srcStartBytes# arrD# dstStartBytes# lenBytes# s#
20952096 , () #)
20962097
2097−-- | Copy two arrays into a newly allocated array.
2098+-- | Copy two arrays into a newly allocated array. If the first array is pinned
2099+-- the spliced array is also pinned.
20982100{-# INLINE spliceCopy #-}
20992101spliceCopy :: forall m a. MonadIO m =>
21002102#ifdef DEVBUILD
@@ -2106,7 +2108,11 @@ spliceCopy arr1 arr2 = liftIO $ do
21062108 start2 = arrStart arr2
21072109 len1 = arrEnd arr1 - start1
21082110 len2 = arrEnd arr2 - start2
2109− newArrContents <- liftIO $ Unboxed.newUnpinnedBytes (len1 + len2)
2111+ let newLen = len1 + len2
2112+ newArrContents <-
2113+ if Unboxed.isPinned (arrContents arr1)
2114+ then Unboxed.newPinnedBytes newLen
2115+ else Unboxed.newUnpinnedBytes newLen
21102116 let len = len1 + len2
21112117 newArr = MutArray newArrContents 0 len len
21122118 putSliceUnsafe arr1 start1 newArr 0 len1
@@ -2169,6 +2175,8 @@ spliceWith sizer dst@(MutArray _ start end bound) src = do
21692175--
21702176-- >>> splice = MutArray.spliceWith (+)
21712177--
2178+-- If the original array is pinned the spliced array is also pinned.
2179+--
21722180-- /Pre-release/
21732181{-# INLINE splice #-}
21742182splice :: (MonadIO m, Unbox a) => MutArray a -> MutArray a -> m (MutArray a)