Skip to content

Commit 2c8b669

Browse files
authored
Merge pull request #302 from treeowl/intmap-inline-map
Rewrite IntMap map so it can inline; define <$
2 parents b2280fc + a4f439c commit 2c8b669

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

Data/IntMap/Base.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ import Data.Utils.StrictPair
248248
import Data.Data (Data(..), Constr, mkConstr, constrIndex, Fixity(Prefix),
249249
DataType, mkDataType)
250250
import GHC.Exts (build)
251+
import Data.Functor ((<$))
251252
#if __GLASGOW_HASKELL__ >= 708
252253
import qualified GHC.Exts as GHCExts
253254
#endif
@@ -1330,11 +1331,11 @@ isSubmapOfBy _ Nil _ = True
13301331
-- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
13311332

13321333
map :: (a -> b) -> IntMap a -> IntMap b
1333-
map f t
1334-
= case t of
1335-
Bin p m l r -> Bin p m (map f l) (map f r)
1336-
Tip k x -> Tip k (f x)
1337-
Nil -> Nil
1334+
map f = go
1335+
where
1336+
go (Bin p m l r) = Bin p m (go l) (go r)
1337+
go (Tip k x) = Tip k (f x)
1338+
go Nil = Nil
13381339

13391340
#ifdef __GLASGOW_HASKELL__
13401341
{-# NOINLINE [1] map #-}
@@ -2096,6 +2097,12 @@ instance Ord a => Ord (IntMap a) where
20962097
instance Functor IntMap where
20972098
fmap = map
20982099

2100+
#ifdef __GLASGOW_HASKELL__
2101+
a <$ Bin p m l r = Bin p m (a <$ l) (a <$ r)
2102+
a <$ Tip k _ = Tip k a
2103+
a <$ Nil = Nil
2104+
#endif
2105+
20992106
{--------------------------------------------------------------------
21002107
Show
21012108
--------------------------------------------------------------------}

Data/IntMap/Strict.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,11 @@ updateMin f = updateMinWithKey (const f)
767767
-- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
768768

769769
map :: (a -> b) -> IntMap a -> IntMap b
770-
map f t
771-
= case t of
772-
Bin p m l r -> Bin p m (map f l) (map f r)
773-
Tip k x -> Tip k $! f x
774-
Nil -> Nil
770+
map f = go
771+
where
772+
go (Bin p m l r) = Bin p m (go l) (go r)
773+
go (Tip k x) = Tip k $! f x
774+
go Nil = Nil
775775

776776
#ifdef __GLASGOW_HASKELL__
777777
{-# NOINLINE [1] map #-}

0 commit comments

Comments
 (0)