[commit: ghc] master: Slightly improve fusion rules for 'take' (2ef997b)
git at git.haskell.org
git at git.haskell.org
Thu Aug 28 11:12:05 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/2ef997b827a5630ad639b5283574a4273cae47ce/ghc
>---------------------------------------------------------------
commit 2ef997b827a5630ad639b5283574a4273cae47ce
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Tue May 13 10:55:33 2014 +0100
Slightly improve fusion rules for 'take'
>---------------------------------------------------------------
2ef997b827a5630ad639b5283574a4273cae47ce
libraries/base/GHC/List.lhs | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/libraries/base/GHC/List.lhs b/libraries/base/GHC/List.lhs
index 9b6cc2e..bcc5fea 100644
--- a/libraries/base/GHC/List.lhs
+++ b/libraries/base/GHC/List.lhs
@@ -385,10 +385,17 @@ takeFoldr (I# n#) xs
takeConst :: a -> Int# -> a
takeConst x _ = x
-{-# NOINLINE [0] takeFB #-}
+{-# INLINE [0] takeFB #-}
takeFB :: (a -> b -> b) -> b -> a -> (Int# -> b) -> Int# -> b
-takeFB c n x xs m | isTrue# (m <=# 1#) = x `c` n
- | otherwise = x `c` xs (m -# 1#)
+-- The \m accounts for the fact that takeFB is used in a higher-order
+-- way by takeFoldr, so it's better to inline. A good example is
+-- take n (repeat x)
+-- for which we get excellent code... but only if we inline takeFB
+-- when given four arguments
+takeFB c n x xs
+ = \ m -> if isTrue# (m <=# 1#)
+ then x `c` n
+ else x `c` xs (m -# 1#)
{-# INLINE [0] take #-}
take (I# n#) xs = takeUInt n# xs
More information about the ghc-commits
mailing list