Commit 68a1e679 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Make absolutely sure that 'done' and 'safeIndex' are strict in the index

This is just to make sure that there is no redundant boxing.
For safeIndex, for example, the error path doesn't evaluate the
index, so it may be passed boxed unless safeIndex is inlined bodily,
which I don't want to rely on.
parent 98aab76a
...@@ -491,7 +491,8 @@ fill marr# (I# i#, e) next ...@@ -491,7 +491,8 @@ fill marr# (I# i#, e) next
{-# INLINE done #-} {-# INLINE done #-}
done :: Ix i => i -> i -> Int -> MutableArray# s e -> STRep s (Array i e) done :: Ix i => i -> i -> Int -> MutableArray# s e -> STRep s (Array i e)
-- See NB on 'fill' -- See NB on 'fill'
done l u n marr# -- Make sure it is strict in 'n'
done l u n@(I# _) marr#
= \s1# -> case unsafeFreezeArray# marr# s1# of = \s1# -> case unsafeFreezeArray# marr# s1# of
(# s2#, arr# #) -> (# s2#, Array l u n arr# #) (# s2#, arr# #) -> (# s2#, Array l u n arr# #)
...@@ -534,11 +535,13 @@ negRange = error "Negative range size" ...@@ -534,11 +535,13 @@ negRange = error "Negative range size"
{-# INLINE[1] safeIndex #-} {-# INLINE[1] safeIndex #-}
-- See Note [Double bounds-checking of index values] -- See Note [Double bounds-checking of index values]
-- Inline *after* (!) so the rules can fire -- Inline *after* (!) so the rules can fire
-- Make sure it is strict in n
safeIndex :: Ix i => (i, i) -> Int -> i -> Int safeIndex :: Ix i => (i, i) -> Int -> i -> Int
safeIndex (l,u) n i = let i' = index (l,u) i safeIndex (l,u) n@(I# _) i
in if (0 <= i') && (i' < n) | (0 <= i') && (i' < n) = i'
then i' | otherwise = badSafeIndex i' n
else badSafeIndex i' n where
i' = index (l,u) i
-- See Note [Double bounds-checking of index values] -- See Note [Double bounds-checking of index values]
{-# RULES {-# RULES
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment