@@ -42,15 +42,12 @@ module Streamly.Internal.Data.Array.Mut.Type
44 -- *** Uninitialized Arrays
44 -- *** Uninitialized Arrays
45− , newPinned
45+ , pinnedNew
46− , newPinnedBytes
46+ , pinnedNewBytes
47− , newAlignedPinned
47+ , pinnedNewAligned
49 , newArrayWith
49 , newArrayWith
51− -- *** Initialized Arrays
52− , withNewArrayUnsafePinned
54 -- *** From streams
51 -- *** From streams
55 , ArrayUnsafe (..)
52 , ArrayUnsafe (..)
56 , writeNWithUnsafe
53 , writeNWithUnsafe
@@ -388,7 +385,7 @@ isPinned MutArray{..} = Unboxed.isPinned arrContents
388-- files and arrays.
385-- files and arrays.
390-- GHC always guarantees word-aligned memory, alignment is important only when
387-- GHC always guarantees word-aligned memory, alignment is important only when
391−-- we need more than that. See stg_newAlignedPinnedByteArrayzh and
388+-- we need more than that. See stg_pinnedNewAlignedByteArrayzh and
392-- allocatePinned in GHC source.
389-- allocatePinned in GHC source.
394-- | @newArrayWith allocator alignment count@ allocates a new array of zero
391-- | @newArrayWith allocator alignment count@ allocates a new array of zero
@@ -441,22 +438,22 @@ newBytesAs ps bytes = do
441-- 'Unboxed' instance of the type.
438-- 'Unboxed' instance of the type.
443-- /Pre-release/
440-- /Pre-release/
444−{-# INLINE newPinnedBytes #-}
441+{-# INLINE pinnedNewBytes #-}
445−newPinnedBytes :: MonadIO m =>
442+pinnedNewBytes :: MonadIO m =>
446#ifdef DEVBUILD
443#ifdef DEVBUILD
447 Unbox a =>
444 Unbox a =>
449 Int -> m (MutArray a)
446 Int -> m (MutArray a)
450−newPinnedBytes = newBytesAs Pinned
447+pinnedNewBytes = newBytesAs Pinned
452-- | Like 'newArrayWith' but using an allocator is a pinned memory allocator and
449-- | Like 'newArrayWith' but using an allocator is a pinned memory allocator and
453-- the alignment is dictated by the 'Unboxed' instance of the type.
450-- the alignment is dictated by the 'Unboxed' instance of the type.
455-- /Internal/
452-- /Internal/
456−{-# INLINE newAlignedPinned #-}
453+{-# INLINE pinnedNewAligned #-}
457−newAlignedPinned :: (MonadIO m, Unbox a) => Int -> Int -> m (MutArray a)
454+pinnedNewAligned :: (MonadIO m, Unbox a) => Int -> Int -> m (MutArray a)
458−newAlignedPinned =
455+pinnedNewAligned =
459− newArrayWith (\s a -> liftIO $ Unboxed.newAlignedPinnedBytes s a)
456+ newArrayWith (\s a -> liftIO $ Unboxed.pinnedNewAlignedBytes s a)
461{-# INLINE newAs #-}
458{-# INLINE newAs #-}
462newAs :: (MonadIO m, Unbox a) => PinnedState -> Int -> m (MutArray a)
459newAs :: (MonadIO m, Unbox a) => PinnedState -> Int -> m (MutArray a)
@@ -471,9 +468,9 @@ newAs ps =
471-- the array is uninitialized and the allocation is aligned as per the 'Unboxed'
468-- the array is uninitialized and the allocation is aligned as per the 'Unboxed'
472-- instance of the type.
469-- instance of the type.
474−{-# INLINE newPinned #-}
471+{-# INLINE pinnedNew #-}
475−newPinned :: forall m a. (MonadIO m, Unbox a) => Int -> m (MutArray a)
472+pinnedNew :: forall m a. (MonadIO m, Unbox a) => Int -> m (MutArray a)
476−newPinned = newAs Pinned
473+pinnedNew = newAs Pinned
478-- | Allocates an empty unpinned array that can hold 'count' items. The memory
475-- | Allocates an empty unpinned array that can hold 'count' items. The memory
479-- of the array is uninitialized.
476-- of the array is uninitialized.
@@ -482,21 +479,6 @@ newPinned = newAs Pinned
482new :: (MonadIO m, Unbox a) => Int -> m (MutArray a)
479new :: (MonadIO m, Unbox a) => Int -> m (MutArray a)
483new = newAs Unpinned
480new = newAs Unpinned
485−-- XXX This should create a full length uninitialzed array so that the pointer
488−-- | Allocate a pinned MutArray of the given size and run an IO action passing
489−-- the array start pointer.
492−{-# INLINE withNewArrayUnsafePinned #-}
493−withNewArrayUnsafePinned ::
494− (MonadIO m, Unbox a) => Int -> (Ptr a -> m ()) -> m (MutArray a)
495−withNewArrayUnsafePinned count f = do
496− arr <- newPinned count
498− $ \p -> f p >> return arr
500-------------------------------------------------------------------------------
482-------------------------------------------------------------------------------
501-- Random writes
483-- Random writes
502-------------------------------------------------------------------------------
484-------------------------------------------------------------------------------
@@ -755,7 +737,7 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do
755 let newCapMaxInBytes = roundUpLargeArray newCapacityInBytes
737 let newCapMaxInBytes = roundUpLargeArray newCapacityInBytes
756 contents <-
738 contents <-
757 if Unboxed.isPinned arrContents
739 if Unboxed.isPinned arrContents
758− then Unboxed.newPinnedBytes newCapMaxInBytes
740+ then Unboxed.pinnedNewBytes newCapMaxInBytes
759 else Unboxed.newUnpinnedBytes newCapMaxInBytes
741 else Unboxed.newUnpinnedBytes newCapMaxInBytes
760 let !(MutableByteArray mbarrFrom#) = arrContents
742 let !(MutableByteArray mbarrFrom#) = arrContents
761 !(MutableByteArray mbarrTo#) = contents
743 !(MutableByteArray mbarrTo#) = contents
@@ -1864,15 +1846,15 @@ writeRevN = writeRevNWith new
1864-- | @pinnedWriteNAligned align n@ folds a maximum of @n@ elements from the
1846-- | @pinnedWriteNAligned align n@ folds a maximum of @n@ elements from the
1865-- input stream to a 'MutArray' aligned to the given size.
1847-- input stream to a 'MutArray' aligned to the given size.
1867−-- >>> pinnedWriteNAligned align = MutArray.writeNWith (MutArray.newAlignedPinned align)
1849+-- >>> pinnedWriteNAligned align = MutArray.writeNWith (MutArray.pinnedNewAligned align)
1868−-- >>> pinnedWriteNAligned align n = MutArray.writeAppendN n (MutArray.newAlignedPinned align n)
1850+-- >>> pinnedWriteNAligned align n = MutArray.writeAppendN n (MutArray.pinnedNewAligned align n)
1870-- /Pre-release/
1852-- /Pre-release/
1872{-# INLINE_NORMAL pinnedWriteNAligned #-}
1854{-# INLINE_NORMAL pinnedWriteNAligned #-}
1873pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
1855pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
1874 => Int -> Int -> Fold m a (MutArray a)
1856 => Int -> Int -> Fold m a (MutArray a)
1875−pinnedWriteNAligned align = writeNWith (newAlignedPinned align)
1857+pinnedWriteNAligned align = writeNWith (pinnedNewAligned align)
1877-- XXX Buffer to a list instead?
1859-- XXX Buffer to a list instead?