[commit: packages/base] master: go-ify foldr2 (4a8ffcf)
git at git.haskell.org
git at git.haskell.org
Tue Jan 28 18:08:21 UTC 2014
Repository : ssh://git@git.haskell.org/base
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/4a8ffcf55c897851b534c700951a0b5bdd43eb97/base
>---------------------------------------------------------------
commit 4a8ffcf55c897851b534c700951a0b5bdd43eb97
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Tue Jan 28 18:09:13 2014 +0000
go-ify foldr2
This helps with the changes in #7994, but might also generally be a good
idea (ignore the runtime):
--------------------------------------------------------------------------------
Program Size Allocs Runtime Elapsed TotalMem
fft2 -0.1% -1.5% 0.07 0.07 +0.0%
fibheaps +0.0% -17.2% 0.03 0.03 +0.0%
fluid +0.5% -0.7% 0.01 0.01 +0.0%
integrate +0.0% -0.9% 0.16 0.16 +0.0%
rewrite +0.0% -1.1% 0.02 0.02 +0.0%
--------------------------------------------------------------------------------
Min -0.1% -17.2% -1.6% +0.0% +0.0%
Max +0.5% +0.0% +107.7% +106.2% +11.3%
Geometric Mean +0.0% -0.2% +23.7% +23.9% +0.1%
>---------------------------------------------------------------
4a8ffcf55c897851b534c700951a0b5bdd43eb97
GHC/List.lhs | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/GHC/List.lhs b/GHC/List.lhs
index 5358f15..b7b78c7 100644
--- a/GHC/List.lhs
+++ b/GHC/List.lhs
@@ -633,11 +633,12 @@ xs !! (I# n0) | isTrue# (n0 <# 0#) = error "Prelude.(!!): negative index\n"
\begin{code}
foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c
-foldr2 _k z [] _ys = z
-foldr2 _k z _xs [] = z
-foldr2 k z (x:xs) (y:ys) = k x y (foldr2 k z xs ys)
-
-{-# NOINLINE [1] foldr2 #-}
+foldr2 k z = go
+ where
+ go [] _ys = z
+ go _xs [] = z
+ go (x:xs) (y:ys) = k x y (go xs ys)
+{-# INLINE [0] foldr2 #-}
foldr2_left :: (a -> b -> c -> d) -> d -> a -> ([b] -> c) -> [b] -> d
foldr2_left _k z _x _r [] = z
More information about the ghc-commits
mailing list