Commit 6ebc2c89 authored by simonpj's avatar simonpj
Browse files

[project @ 1999-05-28 19:20:04 by simonpj]

Make Ix instances more inlinable
parent e3564f89
...@@ -76,10 +76,10 @@ indexError rng i tp ...@@ -76,10 +76,10 @@ indexError rng i tp
---------------------------------------------------------------------- ----------------------------------------------------------------------
instance Ix Char where instance Ix Char where
range (m,n) {-# INLINE range #-}
| m <= n = [m..n] range (m,n) = [m..n]
| otherwise = []
{-# INLINE unsafeIndex #-}
unsafeIndex (m,n) i = fromEnum i - fromEnum m unsafeIndex (m,n) i = fromEnum i - fromEnum m
index b i | inRange b i = unsafeIndex b i index b i | inRange b i = unsafeIndex b i
...@@ -89,10 +89,12 @@ instance Ix Char where ...@@ -89,10 +89,12 @@ instance Ix Char where
---------------------------------------------------------------------- ----------------------------------------------------------------------
instance Ix Int where instance Ix Int where
range (m,n) {-# INLINE range #-}
| m <= n = [m..n] -- The INLINE stops the build in the RHS from getting inlined,
| otherwise = [] -- so that callers can fuse with the result of range
range (m,n) = [m..n]
{-# INLINE unsafeIndex #-}
unsafeIndex (m,n) i = i - m unsafeIndex (m,n) i = i - m
index b i | inRange b i = unsafeIndex b i index b i | inRange b i = unsafeIndex b i
...@@ -103,10 +105,10 @@ instance Ix Int where ...@@ -103,10 +105,10 @@ instance Ix Int where
---------------------------------------------------------------------- ----------------------------------------------------------------------
instance Ix Integer where instance Ix Integer where
range (m,n) {-# INLINE range #-}
| m <= n = [m..n] range (m,n) = [m..n]
| otherwise = []
{-# INLINE unsafeIndex #-}
unsafeIndex (m,n) i = fromInteger (i - m) unsafeIndex (m,n) i = fromInteger (i - m)
index b i | inRange b i = unsafeIndex b i index b i | inRange b i = unsafeIndex b i
...@@ -117,10 +119,10 @@ instance Ix Integer where ...@@ -117,10 +119,10 @@ instance Ix Integer where
---------------------------------------------------------------------- ----------------------------------------------------------------------
instance Ix Bool where -- as derived instance Ix Bool where -- as derived
range (l,u) {-# INLINE range #-}
| l <= u = map toEnum [fromEnum l .. fromEnum u] range (m,n) = [m..n]
| otherwise = []
{-# INLINE unsafeIndex #-}
unsafeIndex (l,_) i = fromEnum i - fromEnum l unsafeIndex (l,_) i = fromEnum i - fromEnum l
index b i | inRange b i = unsafeIndex b i index b i | inRange b i = unsafeIndex b i
...@@ -130,12 +132,15 @@ instance Ix Bool where -- as derived ...@@ -130,12 +132,15 @@ instance Ix Bool where -- as derived
---------------------------------------------------------------------- ----------------------------------------------------------------------
instance Ix Ordering where -- as derived instance Ix Ordering where -- as derived
range (l,u) {-# INLINE range #-}
| l <= u = map toEnum [fromEnum l .. fromEnum u] range (m,n) = [m..n]
| otherwise = []
{-# INLINE unsafeIndex #-}
unsafeIndex (l,_) i = fromEnum i - fromEnum l unsafeIndex (l,_) i = fromEnum i - fromEnum l
index b i | inRange b i = unsafeIndex b i index b i | inRange b i = unsafeIndex b i
| otherwise = indexError b i "Ordering" | otherwise = indexError b i "Ordering"
inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u
---------------------------------------------------------------------- ----------------------------------------------------------------------
......
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