{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}
{-# OPTIONS_GHC -O2 #-}
module GHC.Data.FastMutInt(
FastMutInt, newFastMutInt,
readFastMutInt, writeFastMutInt,
FastMutPtr, newFastMutPtr,
readFastMutPtr, writeFastMutPtr
) where
import GHC.Prelude
import Data.Bits
import GHC.Base
import GHC.Ptr
newFastMutInt :: IO FastMutInt
readFastMutInt :: FastMutInt -> IO Int
writeFastMutInt :: FastMutInt -> Int -> IO ()
newFastMutPtr :: IO FastMutPtr
readFastMutPtr :: FastMutPtr -> IO (Ptr a)
writeFastMutPtr :: FastMutPtr -> Ptr a -> IO ()
data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
newFastMutInt :: IO FastMutInt
newFastMutInt = (State# RealWorld -> (# State# RealWorld, FastMutInt #))
-> IO FastMutInt
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, FastMutInt #))
-> IO FastMutInt)
-> (State# RealWorld -> (# State# RealWorld, FastMutInt #))
-> IO FastMutInt
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
size State# RealWorld
s of { (# State# RealWorld
s, MutableByteArray# RealWorld
arr #) ->
(# State# RealWorld
s, MutableByteArray# RealWorld -> FastMutInt
FastMutInt MutableByteArray# RealWorld
arr #) }
where !(I# Int#
size) = Int -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize (Int
0 :: Int)
readFastMutInt :: FastMutInt -> IO Int
readFastMutInt (FastMutInt MutableByteArray# RealWorld
arr) = (State# RealWorld -> (# State# RealWorld, Int #)) -> IO Int
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Int #)) -> IO Int)
-> (State# RealWorld -> (# State# RealWorld, Int #)) -> IO Int
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case MutableByteArray# RealWorld
-> Int# -> State# RealWorld -> (# State# RealWorld, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readIntArray# MutableByteArray# RealWorld
arr Int#
0# State# RealWorld
s of { (# State# RealWorld
s, Int#
i #) ->
(# State# RealWorld
s, Int# -> Int
I# Int#
i #) }
writeFastMutInt :: FastMutInt -> Int -> IO ()
writeFastMutInt (FastMutInt MutableByteArray# RealWorld
arr) (I# Int#
i) = (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, () #)) -> IO ())
-> (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case MutableByteArray# RealWorld
-> Int# -> Int# -> State# RealWorld -> State# RealWorld
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeIntArray# MutableByteArray# RealWorld
arr Int#
0# Int#
i State# RealWorld
s of { State# RealWorld
s ->
(# State# RealWorld
s, () #) }
data FastMutPtr = FastMutPtr (MutableByteArray# RealWorld)
newFastMutPtr :: IO FastMutPtr
newFastMutPtr = (State# RealWorld -> (# State# RealWorld, FastMutPtr #))
-> IO FastMutPtr
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, FastMutPtr #))
-> IO FastMutPtr)
-> (State# RealWorld -> (# State# RealWorld, FastMutPtr #))
-> IO FastMutPtr
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
size State# RealWorld
s of { (# State# RealWorld
s, MutableByteArray# RealWorld
arr #) ->
(# State# RealWorld
s, MutableByteArray# RealWorld -> FastMutPtr
FastMutPtr MutableByteArray# RealWorld
arr #) }
where !(I# Int#
size) = Int -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize (Int
0 :: Int)
readFastMutPtr :: forall a. FastMutPtr -> IO (Ptr a)
readFastMutPtr (FastMutPtr MutableByteArray# RealWorld
arr) = (State# RealWorld -> (# State# RealWorld, Ptr a #)) -> IO (Ptr a)
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Ptr a #)) -> IO (Ptr a))
-> (State# RealWorld -> (# State# RealWorld, Ptr a #))
-> IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case MutableByteArray# RealWorld
-> Int# -> State# RealWorld -> (# State# RealWorld, Addr# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Addr# #)
readAddrArray# MutableByteArray# RealWorld
arr Int#
0# State# RealWorld
s of { (# State# RealWorld
s, Addr#
i #) ->
(# State# RealWorld
s, Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
i #) }
writeFastMutPtr :: forall a. FastMutPtr -> Ptr a -> IO ()
writeFastMutPtr (FastMutPtr MutableByteArray# RealWorld
arr) (Ptr Addr#
i) = (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, () #)) -> IO ())
-> (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case MutableByteArray# RealWorld
-> Int# -> Addr# -> State# RealWorld -> State# RealWorld
forall d.
MutableByteArray# d -> Int# -> Addr# -> State# d -> State# d
writeAddrArray# MutableByteArray# RealWorld
arr Int#
0# Addr#
i State# RealWorld
s of { State# RealWorld
s ->
(# State# RealWorld
s, () #) }