{-# LANGUAGE UnboxedTuples #-}
#include "inline.hs"
module Streamly.Internal.Data.Array.Prim.Mut.Type
(
Array (..)
, newArray
, unsafeWriteIndex
, spliceTwo
, unsafeCopy
, fromListM
, fromListNM
, fromStreamDN
, fromStreamD
, fromStreamDArraysOf
, packArraysChunksOf
, lpackArraysChunksOf
#if !defined(mingw32_HOST_OS)
#endif
, unsafeReadIndex
, length
, byteLength
, writeN
, ArrayUnsafe(..)
, writeNUnsafe
, write
, resizeArray
, shrinkArray
)
where
#include "Streamly/Internal/Data/Array/Prim/MutTypesInclude.hs"
{-# INLINE newArray #-}
newArray ::
forall m a. (MonadIO m, Prim a)
=> Int
-> m (Array a)
newArray :: forall (m :: * -> *) a. (MonadIO m, Prim a) => Int -> m (Array a)
newArray (I# Int#
n#) =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
let bytes :: Int#
bytes = Int#
n# Int# -> Int# -> Int#
*# forall a. Prim a => a -> Int#
sizeOf# (forall a. HasCallStack => a
undefined :: a)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState IO)
s# ->
case forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
bytes State# (PrimState IO)
s# of
(# State# RealWorld
s1#, MutableByteArray# RealWorld
arr# #) -> (# State# RealWorld
s1#, forall a. MutableByteArray# RealWorld -> Array a
Array MutableByteArray# RealWorld
arr# #)
{-# INLINE resizeArray #-}
resizeArray ::
forall m a. (MonadIO m, Prim a)
=> Array a
-> Int
-> m (Array a)
resizeArray :: forall (m :: * -> *) a.
(MonadIO m, Prim a) =>
Array a -> Int -> m (Array a)
resizeArray (Array MutableByteArray# RealWorld
arr#) (I# Int#
n#) =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
let bytes :: Int#
bytes = Int#
n# Int# -> Int# -> Int#
*# forall a. Prim a => a -> Int#
sizeOf# (forall a. HasCallStack => a
undefined :: a)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState IO)
s# ->
case forall d.
MutableByteArray# d
-> Int# -> State# d -> (# State# d, MutableByteArray# d #)
resizeMutableByteArray# MutableByteArray# RealWorld
arr# Int#
bytes State# (PrimState IO)
s# of
(# State# RealWorld
s1#, MutableByteArray# RealWorld
arr1# #) -> (# State# RealWorld
s1#, forall a. MutableByteArray# RealWorld -> Array a
Array MutableByteArray# RealWorld
arr1# #)