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
31 #ifdef __GLASGOW_HASKELL__
32 data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
34 newFastMutInt :: IO FastMutInt
35 newFastMutInt = IO $ \s ->
36 case newByteArray# size s of { (# s, arr #) ->
37 (# s, FastMutInt arr #) }
38 where I# size = SIZEOF_HSINT
40 readFastMutInt :: FastMutInt -> IO Int
41 readFastMutInt (FastMutInt arr) = IO $ \s ->
42 case readIntArray# arr 0# s of { (# s, i #) ->
45 writeFastMutInt :: FastMutInt -> Int -> IO ()
46 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s ->
47 case writeIntArray# arr 0# i s of { s ->
50 incFastMutInt :: FastMutInt -> IO Int -- Returns original value
51 incFastMutInt (FastMutInt arr) = IO $ \s ->
52 case readIntArray# arr 0# s of { (# s, i #) ->
53 case writeIntArray# arr 0# (i +# 1#) s of { s ->
56 incFastMutIntBy :: FastMutInt -> Int -> IO Int -- Returns original value
57 incFastMutIntBy (FastMutInt arr) (I# n) = IO $ \s ->
58 case readIntArray# arr 0# s of { (# s, i #) ->
59 case writeIntArray# arr 0# (i +# n) s of { s ->