@@ -217,6 +217,7 @@ writeLastN n = FL.rmapM f (RB.writeLastN n)
217 arr <- RB.toMutArray 0 n rb
217 arr <- RB.toMutArray 0 n rb
218 return $ unsafeFreeze arr
218 return $ unsafeFreeze arr
220+{-# INLINE sliceUnsafe #-}
220sliceUnsafe :: Int -> Int -> Array a -> Array a
221sliceUnsafe :: Int -> Int -> Array a -> Array a
221sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
222sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
@@ -226,6 +227,7 @@ sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
227-- | Truncate the array at the beginning and end as long as the predicate
228-- | Truncate the array at the beginning and end as long as the predicate
228-- holds true. Returns a slice of the original array.
229-- holds true. Returns a slice of the original array.
229strip :: (a -> Bool) -> Array a -> Array a
231strip :: (a -> Bool) -> Array a -> Array a
230strip p arr =
232strip p arr =
231 let lastIndex = length arr - 1
233 let lastIndex = length arr - 1
@@ -259,46 +261,43 @@ strip p arr =
259-------------------------------------------------------------------------------
261-------------------------------------------------------------------------------
261instance Eq a => Eq (Array a) where
263instance Eq a => Eq (Array a) where
262− a1 == a2 = lenA1 == lenA2 && loop (lenA1 - 1)
264+ {-# INLINE (==) #-}
266+ unsafeInlineIO $! unsafeThaw arr1 `MArray.eq` unsafeThaw arr2
264− where
268+instance Ord a => Ord (Array a) where
269+ {-# INLINE compare #-}
271+ unsafeInlineIO $! unsafeThaw arr1 `MArray.cmp` unsafeThaw arr2
266− lenA1 = length a1
273+ -- Default definitions defined in base do not have an INLINE on them, so we
267− lenA2 = length a2
274+ -- replicate them here with an INLINE.
276+ x < y = case compare x y of { LT -> True; _ -> False }
269− loop i
278+ {-# INLINE (<=) #-}
270− | i < 0 = True
279+ x <= y = case compare x y of { GT -> False; _ -> True }
272− let v1 = getIndexUnsafe i a1
273− v2 = getIndexUnsafe i a2
274− in v1 == v2 && loop (i - 1)
276−instance Ord a => Ord (Array a) where
281+ {-# INLINE (>) #-}
278− case compare lenA1 lenA2 of
282+ x > y = case compare x y of { GT -> True; _ -> False }
280− GT -> GT
284+ {-# INLINE (>=) #-}
281− EQ -> loop 0
285+ x >= y = case compare x y of { LT -> False; _ -> True }
283− where
287+ -- These two default methods use '<=' rather than 'compare'
284−
288+ -- because the latter is often more expensive
285− lenA1 = length a1
289+ {-# INLINE max #-}
286− lenA2 = length a2
290+ max x y = if x <= y then y else x
288− loop i
292+ {-# INLINE min #-}
289− | i >= lenA1 = EQ
293+ min x y = if x <= y then x else y
291− let v1 = getIndexUnsafe i a1
292− v2 = getIndexUnsafe i a2
293− in case compare v1 v2 of
298instance Show a => Show (Array a) where
295instance Show a => Show (Array a) where
299 show arr = "fromList " ++ show (toList arr)
297 show arr = "fromList " ++ show (toList arr)
301instance Read a => Read (Array a) where
299instance Read a => Read (Array a) where
300+ {-# INLINE readPrec #-}
302 readPrec = do
301 readPrec = do
303 fromListWord <- replicateM 9 ReadPrec.get
302 fromListWord <- replicateM 9 ReadPrec.get
304 if fromListWord == "fromList "
303 if fromListWord == "fromList "