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
29 #if __GLASGOW_HASKELL__ < 411
30 newByteArray# = newCharArray#
35 #ifdef __GLASGOW_HASKELL__
36 data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
38 newFastMutInt :: IO FastMutInt
39 newFastMutInt = IO $ \s ->
40 case newByteArray# size s of { (# s, arr #) ->
41 (# s, FastMutInt arr #) }
42 where I# size = SIZEOF_HSINT
44 readFastMutInt :: FastMutInt -> IO Int
45 readFastMutInt (FastMutInt arr) = IO $ \s ->
46 case readIntArray# arr 0# s of { (# s, i #) ->
49 writeFastMutInt :: FastMutInt -> Int -> IO ()
50 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s ->
51 case writeIntArray# arr 0# i s of { s ->
54 incFastMutInt :: FastMutInt -> IO Int -- Returns original value
55 incFastMutInt (FastMutInt arr) = IO $ \s ->
56 case readIntArray# arr 0# s of { (# s, i #) ->
57 case writeIntArray# arr 0# (i +# 1#) s of { s ->
60 incFastMutIntBy :: FastMutInt -> Int -> IO Int -- Returns original value
61 incFastMutIntBy (FastMutInt arr) (I# n) = IO $ \s ->
62 case readIntArray# arr 0# s of { (# s, i #) ->
63 case writeIntArray# arr 0# (i +# n) s of { s ->