@@ -61,31 +61,21 @@ import Text.ParserCombinators.ReadP
6161
6262-- | Boxed arrays
6363data Array a = Array
64- { array# :: Array# a
65- #if (__GLASGOW_HASKELL__ < 702)
66- , sizeofArray :: {-# UNPACK #-} ! Int
67- # endif
68- }
64+ { array# :: Array# a }
6965 deriving ( Typeable )
7066
7167-- | Mutable boxed arrays associated with a primitive state token.
7268data MutableArray s a = MutableArray
73- { marray# :: MutableArray# s a
74- #if (__GLASGOW_HASKELL__ < 702)
75- , sizeofMutableArray :: {-# UNPACK #-} ! Int
76- # endif
77- }
69+ { marray# :: MutableArray# s a }
7870 deriving ( Typeable )
7971
80- #if (__GLASGOW_HASKELL__ >= 702)
8172sizeofArray :: Array a -> Int
8273sizeofArray a = I # (sizeofArray# (array# a))
8374{-# INLINE sizeofArray #-}
8475
8576sizeofMutableArray :: MutableArray s a -> Int
8677sizeofMutableArray a = I # (sizeofMutableArray# (marray# a))
8778{-# INLINE sizeofMutableArray #-}
88- #endif
8979
9080-- | Create a new mutable array of the specified size and initialise all
9181-- elements with the given value.
@@ -95,9 +85,6 @@ newArray (I# n#) x = primitive
9585 (\ s# -> case newArray# n# x s# of
9686 (# s'# , arr# # ) ->
9787 let ma = MutableArray arr#
98- #if (__GLASGOW_HASKELL__ < 702)
99- (I # n# )
100- #endif
10188 in (# s'# , ma # ))
10289
10390-- | Read a value from the array at the given index.
@@ -161,16 +148,9 @@ freezeArray
161148 -> Int -- ^ length
162149 -> m (Array a )
163150{-# INLINE freezeArray #-}
164- #if (__GLASGOW_HASKELL__ >= 702)
165151freezeArray (MutableArray ma# ) (I # off# ) (I # len# ) =
166152 primitive $ \ s -> case freezeArray# ma# off# len# s of
167153 (# s', a# # ) -> (# s', Array a# # )
168- #else
169- freezeArray src off len = do
170- dst <- newArray len (die " freezeArray" " impossible" )
171- copyMutableArray dst 0 src off len
172- unsafeFreezeArray dst
173- #endif
174154
175155-- | Convert a mutable array to an immutable one without copying. The
176156-- array should not be modified after the conversion.
@@ -180,9 +160,6 @@ unsafeFreezeArray arr
180160 = primitive (\ s# -> case unsafeFreezeArray# (marray# arr) s# of
181161 (# s'# , arr'# # ) ->
182162 let a = Array arr'#
183- #if (__GLASGOW_HASKELL__ < 702)
184- (sizeofMutableArray arr)
185- #endif
186163 in (# s'# , a # ))
187164
188165-- | Create a mutable array from a slice of an immutable array.
@@ -196,16 +173,9 @@ thawArray
196173 -> Int -- ^ length
197174 -> m (MutableArray (PrimState m ) a )
198175{-# INLINE thawArray #-}
199- #if (__GLASGOW_HASKELL__ >= 702)
200176thawArray (Array a# ) (I # off# ) (I # len# ) =
201177 primitive $ \ s -> case thawArray# a# off# len# s of
202178 (# s', ma# # ) -> (# s', MutableArray ma# # )
203- #else
204- thawArray src off len = do
205- dst <- newArray len (die " thawArray" " impossible" )
206- copyArray dst 0 src off len
207- return dst
208- #endif
209179
210180-- | Convert an immutable array to an mutable one without copying. The
211181-- immutable array should not be used after the conversion.
@@ -215,9 +185,6 @@ unsafeThawArray a
215185 = primitive (\ s# -> case unsafeThawArray# (array# a) s# of
216186 (# s'# , arr'# # ) ->
217187 let ma = MutableArray arr'#
218- #if (__GLASGOW_HASKELL__ < 702)
219- (sizeofArray a)
220- #endif
221188 in (# s'# , ma # ))
222189
223190-- | Check whether the two arrays refer to the same memory block.
@@ -282,15 +249,8 @@ cloneArray :: Array a -- ^ source array
282249 -> Int -- ^ number of elements to copy
283250 -> Array a
284251{-# INLINE cloneArray #-}
285- #if __GLASGOW_HASKELL__ >= 702
286252cloneArray (Array arr# ) (I # off# ) (I # len# )
287253 = case cloneArray# arr# off# len# of arr'# -> Array arr'#
288- #else
289- cloneArray arr off len = runST $ do
290- marr2 <- newArray len $ die " cloneArray" " impossible"
291- copyArray marr2 0 arr off len
292- unsafeFreezeArray marr2
293- #endif
294254
295255-- | Return a newly allocated MutableArray. with the specified subrange of
296256-- the provided MutableArray. The provided MutableArray should contain the
@@ -301,21 +261,9 @@ cloneMutableArray :: PrimMonad m
301261 -> Int -- ^ number of elements to copy
302262 -> m (MutableArray (PrimState m ) a )
303263{-# INLINE cloneMutableArray #-}
304- #if __GLASGOW_HASKELL__ >= 702
305264cloneMutableArray (MutableArray arr# ) (I # off# ) (I # len# ) = primitive
306265 (\ s# -> case cloneMutableArray# arr# off# len# s# of
307266 (# s'# , arr'# # ) -> (# s'# , MutableArray arr'# # ))
308- #else
309- cloneMutableArray marr off len = do
310- marr2 <- newArray len $ die " cloneMutableArray" " impossible"
311- let go ! i ! j c
312- | c >= len = return marr2
313- | otherwise = do
314- b <- readArray marr i
315- writeArray marr2 j b
316- go (i+ 1 ) (j+ 1 ) (c+ 1 )
317- go off 0 0
318- #endif
319267
320268emptyArray :: Array a
321269emptyArray =
0 commit comments