@@ -773,6 +773,7 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do
773-- down to multiples of array size. If the new size is more than
773-- down to multiples of array size. If the new size is more than
774-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
774-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
776+-- If the original array is pinned, the newly allocated array is also pinned.
776{-# INLINABLE realloc #-}
777{-# INLINABLE realloc #-}
777realloc :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (MutArray a)
778realloc :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (MutArray a)
778realloc bytes arr = liftIO $ reallocExplicit (SIZE_OF(a)) bytes arr
779realloc bytes arr = liftIO $ reallocExplicit (SIZE_OF(a)) bytes arr
@@ -2094,7 +2095,8 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
2094 arrS# srcStartBytes# arrD# dstStartBytes# lenBytes# s#
2095 arrS# srcStartBytes# arrD# dstStartBytes# lenBytes# s#
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.
2098{-# INLINE spliceCopy #-}
2100{-# INLINE spliceCopy #-}
2099spliceCopy :: forall m a. MonadIO m =>
2101spliceCopy :: forall m a. MonadIO m =>
2100#ifdef DEVBUILD
2102#ifdef DEVBUILD
@@ -2106,7 +2108,11 @@ spliceCopy arr1 arr2 = liftIO $ do
2106 start2 = arrStart arr2
2108 start2 = arrStart arr2
2107 len1 = arrEnd arr1 - start1
2109 len1 = arrEnd arr1 - start1
2108 len2 = arrEnd arr2 - start2
2110 len2 = arrEnd arr2 - start2
2111+ let newLen = len1 + len2
2109− newArrContents <- liftIO $ Unboxed.newUnpinnedBytes (len1 + len2)
2112+ newArrContents <-
2113+ if Unboxed.isPinned (arrContents arr1)
2114+ then Unboxed.newPinnedBytes newLen
2115+ else Unboxed.newUnpinnedBytes newLen
2110 let len = len1 + len2
2116 let len = len1 + len2
2111 newArr = MutArray newArrContents 0 len len
2117 newArr = MutArray newArrContents 0 len len
2112 putSliceUnsafe arr1 start1 newArr 0 len1
2118 putSliceUnsafe arr1 start1 newArr 0 len1
@@ -2169,6 +2175,8 @@ spliceWith sizer dst@(MutArray _ start end bound) src = do
2170-- >>> splice = MutArray.spliceWith (+)
2176-- >>> splice = MutArray.spliceWith (+)
2178+-- If the original array is pinned the spliced array is also pinned.
2172-- /Pre-release/
2180-- /Pre-release/
2173{-# INLINE splice #-}
2181{-# INLINE splice #-}
2174splice :: (MonadIO m, Unbox a) => MutArray a -> MutArray a -> m (MutArray a)
2182splice :: (MonadIO m, Unbox a) => MutArray a -> MutArray a -> m (MutArray a)