{-# 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 :: Int -> m (Array a)
newArray (I# Int#
n#) =
IO (Array a) -> m (Array a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Array a) -> m (Array a)) -> IO (Array a) -> m (Array a)
forall a b. (a -> b) -> a -> b
$ do
let bytes :: Int#
bytes = Int#
n# Int# -> Int# -> Int#
*# a -> Int#
forall a. Prim a => a -> Int#
sizeOf# (a
forall a. HasCallStack => a
undefined :: a)
(State# (PrimState IO) -> (# State# (PrimState IO), Array a #))
-> IO (Array a)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive ((State# (PrimState IO) -> (# State# (PrimState IO), Array a #))
-> IO (Array a))
-> (State# (PrimState IO) -> (# State# (PrimState IO), Array a #))
-> IO (Array a)
forall a b. (a -> b) -> a -> b
$ \State# (PrimState IO)
s# ->
case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
bytes State# RealWorld
State# (PrimState IO)
s# of
(# State# RealWorld
s1#, MutableByteArray# RealWorld
arr# #) -> (# State# RealWorld
State# (PrimState IO)
s1#, MutableByteArray# RealWorld -> Array a
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 :: Array a -> Int -> m (Array a)
resizeArray (Array MutableByteArray# RealWorld
arr#) (I# Int#
n#) =
IO (Array a) -> m (Array a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Array a) -> m (Array a)) -> IO (Array a) -> m (Array a)
forall a b. (a -> b) -> a -> b
$ do
let bytes :: Int#
bytes = Int#
n# Int# -> Int# -> Int#
*# a -> Int#
forall a. Prim a => a -> Int#
sizeOf# (a
forall a. HasCallStack => a
undefined :: a)
(State# (PrimState IO) -> (# State# (PrimState IO), Array a #))
-> IO (Array a)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive ((State# (PrimState IO) -> (# State# (PrimState IO), Array a #))
-> IO (Array a))
-> (State# (PrimState IO) -> (# State# (PrimState IO), Array a #))
-> IO (Array a)
forall a b. (a -> b) -> a -> b
$ \State# (PrimState IO)
s# ->
case MutableByteArray# RealWorld
-> Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d.
MutableByteArray# d
-> Int# -> State# d -> (# State# d, MutableByteArray# d #)
resizeMutableByteArray# MutableByteArray# RealWorld
arr# Int#
bytes State# RealWorld
State# (PrimState IO)
s# of
(# State# RealWorld
s1#, MutableByteArray# RealWorld
arr1# #) -> (# State# RealWorld
State# (PrimState IO)
s1#, MutableByteArray# RealWorld -> Array a
forall a. MutableByteArray# RealWorld -> Array a
Array MutableByteArray# RealWorld
arr1# #)