@@ -217,6 +217,7 @@ writeLastN n = FL.rmapM f (RB.writeLastN n)
217217 arr <- RB.toMutArray 0 n rb
218218 return $ unsafeFreeze arr
219219
220+{-# INLINE sliceUnsafe #-}
220221sliceUnsafe :: Int -> Int -> Array a -> Array a
221222sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
222223
@@ -226,6 +227,7 @@ sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
226227
227228-- | Truncate the array at the beginning and end as long as the predicate
228229-- holds true. Returns a slice of the original array.
230+{-# INLINE strip #-}
229231strip :: (a -> Bool) -> Array a -> Array a
230232strip p arr =
231233 let lastIndex = length arr - 1
@@ -259,46 +261,43 @@ strip p arr =
259261-------------------------------------------------------------------------------
260262
261263instance Eq a => Eq (Array a) where
262− a1 == a2 = lenA1 == lenA2 && loop (lenA1 - 1)
264+ {-# INLINE (==) #-}
265+ arr1 == arr2 =
266+ unsafeInlineIO $! unsafeThaw arr1 `MArray.eq` unsafeThaw arr2
263267
264− where
268+instance Ord a => Ord (Array a) where
269+ {-# INLINE compare #-}
270+ compare arr1 arr2 =
271+ unsafeInlineIO $! unsafeThaw arr1 `MArray.cmp` unsafeThaw arr2
265272
266− lenA1 = length a1
267− lenA2 = length a2
273+ -- Default definitions defined in base do not have an INLINE on them, so we
274+ -- replicate them here with an INLINE.
275+ {-# INLINE (<) #-}
276+ x < y = case compare x y of { LT -> True; _ -> False }
268277
269− loop i
270− | i < 0 = True
271− | otherwise =
272− let v1 = getIndexUnsafe i a1
273− v2 = getIndexUnsafe i a2
274− in v1 == v2 && loop (i - 1)
278+ {-# INLINE (<=) #-}
279+ x <= y = case compare x y of { GT -> False; _ -> True }
275280
276−instance Ord a => Ord (Array a) where
277− compare a1 a2 =
278− case compare lenA1 lenA2 of
279− LT -> LT
280− GT -> GT
281− EQ -> loop 0
282−
283− where
284−
285− lenA1 = length a1
286− lenA2 = length a2
287−
288− loop i
289− | i >= lenA1 = EQ
290− | otherwise =
291− let v1 = getIndexUnsafe i a1
292− v2 = getIndexUnsafe i a2
293− in case compare v1 v2 of
294− LT -> LT
295− GT -> GT
296− EQ -> loop (i + 1)
281+ {-# INLINE (>) #-}
282+ x > y = case compare x y of { GT -> True; _ -> False }
283+
284+ {-# INLINE (>=) #-}
285+ x >= y = case compare x y of { LT -> False; _ -> True }
286+
287+ -- These two default methods use '<=' rather than 'compare'
288+ -- because the latter is often more expensive
289+ {-# INLINE max #-}
290+ max x y = if x <= y then y else x
291+
292+ {-# INLINE min #-}
293+ min x y = if x <= y then x else y
297294
298295instance Show a => Show (Array a) where
296+ {-# INLINE show #-}
299297 show arr = "fromList " ++ show (toList arr)
300298
301299instance Read a => Read (Array a) where
300+ {-# INLINE readPrec #-}
302301 readPrec = do
303302 fromListWord <- replicateM 9 ReadPrec.get
304303 if fromListWord == "fromList "