[commit: containers] master: Manually inline {Map, IntMap}.map. (af732b9)

Paolo Capriotti <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.libraries
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/packages/containers

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/af732b9bc06273684d821e75f93f424ae2141d6e

>---------------------------------------------------------------

commit af732b9bc06273684d821e75f93f424ae2141d6e
Author: Milan Straka <[email protected]>
Date:   Sun Apr 22 18:06:21 2012 +0200

    Manually inline {Map,IntMap}.map.

>---------------------------------------------------------------

 Data/IntMap/Base.hs   |    6 +++++-
 Data/IntMap/Strict.hs |    6 +++++-
 Data/Map/Base.hs      |    3 ++-
 Data/Map/Strict.hs    |    3 ++-
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/Data/IntMap/Base.hs b/Data/IntMap/Base.hs
index f8c026c..f2ae1a8 100644
--- a/Data/IntMap/Base.hs
+++ b/Data/IntMap/Base.hs
@@ -1125,7 +1125,11 @@ isSubmapOfBy _         Nil _           = True
 -- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
 
 map :: (a -> b) -> IntMap a -> IntMap b
-map f = mapWithKey (\_ x -> f x)
+map f t
+  = case t of
+      Bin p m l r -> Bin p m (map f l) (map f r)
+      Tip k x     -> Tip k (f x)
+      Nil         -> Nil
 
 -- | /O(n)/. Map a function over all values in the map.
 --
diff --git a/Data/IntMap/Strict.hs b/Data/IntMap/Strict.hs
index e9ebadf..77a8d10 100644
--- a/Data/IntMap/Strict.hs
+++ b/Data/IntMap/Strict.hs
@@ -692,7 +692,11 @@ updateMin f = updateMinWithKey (const f)
 -- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
 
 map :: (a -> b) -> IntMap a -> IntMap b
-map f = mapWithKey (\_ x -> f x)
+map f t
+  = case t of
+      Bin p m l r -> Bin p m (map f l) (map f r)
+      Tip k x     -> Tip k $! f x
+      Nil         -> Nil
 
 -- | /O(n)/. Map a function over all values in the map.
 --
diff --git a/Data/Map/Base.hs b/Data/Map/Base.hs
index 966cba7..2d7dd07 100644
--- a/Data/Map/Base.hs
+++ b/Data/Map/Base.hs
@@ -1511,7 +1511,8 @@ mapEitherWithKey f (Bin _ kx x l r) = case f kx x of
 -- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
 
 map :: (a -> b) -> Map k a -> Map k b
-map f = mapWithKey (\_ x -> f x)
+map _ Tip = Tip
+map f (Bin sx kx x l r) = Bin sx kx (f x) (map f l) (map f r)
 
 -- | /O(n)/. Map a function over all values in the map.
 --
diff --git a/Data/Map/Strict.hs b/Data/Map/Strict.hs
index 6cc160f..637c5f9 100644
--- a/Data/Map/Strict.hs
+++ b/Data/Map/Strict.hs
@@ -901,7 +901,8 @@ mapEitherWithKey f (Bin _ kx x l r) = case f kx x of
 -- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
 
 map :: (a -> b) -> Map k a -> Map k b
-map f = mapWithKey (\_ x -> f x)
+map _ Tip = Tip
+map f (Bin sx kx x l r) = let x' = f x in x' `seq` Bin sx kx x' (map f l) (map f r)
 
 -- | /O(n)/. Map a function over all values in the map.
 --
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.