[commit: containers] master: Improve Int{Map,Set}.fold*. (c0e28dc)
Paolo Capriotti
p.capriotti at gmail.com
Tue May 8 00:55:10 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/containers
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/c0e28dc571cc0a4bcfab6fd81458758e6061703b
>---------------------------------------------------------------
commit c0e28dc571cc0a4bcfab6fd81458758e6061703b
Author: Milan Straka <fox at ucw.cz>
Date: Sun Mar 4 16:24:52 2012 +0100
Improve Int{Map,Set}.fold*.
Improve Int{Map,Set}.fold* defitions to be inlinable with
two arguments only.
Otherwise GHC inlined toAscList, toDescList _and after that_ inlined
the fold, resulting in useless code growth.
>---------------------------------------------------------------
Data/IntMap/Base.hs | 16 ++++++++--------
Data/IntSet.hs | 8 ++++----
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/Data/IntMap/Base.hs b/Data/IntMap/Base.hs
index fc46f83..2cda65f 100644
--- a/Data/IntMap/Base.hs
+++ b/Data/IntMap/Base.hs
@@ -1383,7 +1383,7 @@ splitLookup k t =
-- > let f a len = len + (length a)
-- > foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
foldr :: (a -> b -> b) -> b -> IntMap a -> b
-foldr f z t =
+foldr f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z l) r -- put negative numbers before
_ -> go z t
where
@@ -1396,7 +1396,7 @@ foldr f z t =
-- evaluated before using the result in the next application. This
-- function is strict in the starting value.
foldr' :: (a -> b -> b) -> b -> IntMap a -> b
-foldr' f z t =
+foldr' f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z l) r -- put negative numbers before
_ -> go z t
where
@@ -1416,7 +1416,7 @@ foldr' f z t =
-- > let f len a = len + (length a)
-- > foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
foldl :: (a -> b -> a) -> a -> IntMap b -> a
-foldl f z t =
+foldl f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z r) l -- put negative numbers before
_ -> go z t
where
@@ -1429,7 +1429,7 @@ foldl f z t =
-- evaluated before using the result in the next application. This
-- function is strict in the starting value.
foldl' :: (a -> b -> a) -> a -> IntMap b -> a
-foldl' f z t =
+foldl' f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z r) l -- put negative numbers before
_ -> go z t
where
@@ -1450,7 +1450,7 @@ foldl' f z t =
-- > let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
-- > foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
foldrWithKey :: (Int -> a -> b -> b) -> b -> IntMap a -> b
-foldrWithKey f z t =
+foldrWithKey f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z l) r -- put negative numbers before
_ -> go z t
where
@@ -1463,7 +1463,7 @@ foldrWithKey f z t =
-- evaluated before using the result in the next application. This
-- function is strict in the starting value.
foldrWithKey' :: (Int -> a -> b -> b) -> b -> IntMap a -> b
-foldrWithKey' f z t =
+foldrWithKey' f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z l) r -- put negative numbers before
_ -> go z t
where
@@ -1484,7 +1484,7 @@ foldrWithKey' f z t =
-- > let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
-- > foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)"
foldlWithKey :: (a -> Int -> b -> a) -> a -> IntMap b -> a
-foldlWithKey f z t =
+foldlWithKey f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z r) l -- put negative numbers before
_ -> go z t
where
@@ -1497,7 +1497,7 @@ foldlWithKey f z t =
-- evaluated before using the result in the next application. This
-- function is strict in the starting value.
foldlWithKey' :: (a -> Int -> b -> a) -> a -> IntMap b -> a
-foldlWithKey' f z t =
+foldlWithKey' f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z r) l -- put negative numbers before
_ -> go z t
where
diff --git a/Data/IntSet.hs b/Data/IntSet.hs
index 10d7b85..c22dbb4 100644
--- a/Data/IntSet.hs
+++ b/Data/IntSet.hs
@@ -714,7 +714,7 @@ fold = foldr
--
-- > toAscList set = foldr (:) [] set
foldr :: (Int -> b -> b) -> b -> IntSet -> b
-foldr f z t =
+foldr f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z l) r -- put negative numbers before
_ -> go z t
where
@@ -727,7 +727,7 @@ foldr f z t =
-- evaluated before using the result in the next application. This
-- function is strict in the starting value.
foldr' :: (Int -> b -> b) -> b -> IntSet -> b
-foldr' f z t =
+foldr' f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z l) r -- put negative numbers before
_ -> go z t
where
@@ -744,7 +744,7 @@ foldr' f z t =
--
-- > toDescList set = foldl (flip (:)) [] set
foldl :: (a -> Int -> a) -> a -> IntSet -> a
-foldl f z t =
+foldl f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z r) l -- put negative numbers before
_ -> go z t
where
@@ -758,7 +758,7 @@ foldl f z t =
-- evaluated before using the result in the next application. This
-- function is strict in the starting value.
foldl' :: (a -> Int -> a) -> a -> IntSet -> a
-foldl' f z t =
+foldl' f z = \t -> -- Use lambda t to be inlinable with two arguments only.
case t of Bin _ m l r | m < 0 -> go (go z r) l -- put negative numbers before
_ -> go z t
where
More information about the Cvs-libraries
mailing list