3 -- (c) The University of Glasgow 2002
5 -- Unboxed mutable Ints
9 FastMutInt, newFastMutInt,
10 readFastMutInt, writeFastMutInt,
11 incFastMutInt, incFastMutIntBy
17 #define SIZEOF_HSINT INT_SIZE_IN_BYTES
21 #if __GLASGOW_HASKELL__ < 503
30 #ifdef __GLASGOW_HASKELL__
31 data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
33 newFastMutInt :: IO FastMutInt
34 newFastMutInt = IO $ \s ->
35 case newByteArray# size s of { (# s, arr #) ->
36 (# s, FastMutInt arr #) }
37 where I# size = SIZEOF_HSINT
39 readFastMutInt :: FastMutInt -> IO Int
40 readFastMutInt (FastMutInt arr) = IO $ \s ->
41 case readIntArray# arr 0# s of { (# s, i #) ->
44 writeFastMutInt :: FastMutInt -> Int -> IO ()
45 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s ->
46 case writeIntArray# arr 0# i s of { s ->
49 incFastMutInt :: FastMutInt -> IO Int -- Returns original value
50 incFastMutInt (FastMutInt arr) = IO $ \s ->
51 case readIntArray# arr 0# s of { (# s, i #) ->
52 case writeIntArray# arr 0# (i +# 1#) s of { s ->
55 incFastMutIntBy :: FastMutInt -> Int -> IO Int -- Returns original value
56 incFastMutIntBy (FastMutInt arr) (I# n) = IO $ \s ->
57 case readIntArray# arr 0# s of { (# s, i #) ->
58 case writeIntArray# arr 0# (i +# n) s of { s ->