[commit: ghc] master: Use better map operations in CoreMonad (d5e9b7f)

git at git.haskell.org git at git.haskell.org
Wed Feb 8 02:34:50 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d5e9b7f5b84440e0e81515773c8fa31cbaebfd57/ghc

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

commit d5e9b7f5b84440e0e81515773c8fa31cbaebfd57
Author: David Feuer <david.feuer at gmail.com>
Date:   Tue Feb 7 21:34:00 2017 -0500

    Use better map operations in CoreMonad
    
    Use strict `unionWith` where apparently appropriate, and use
    strict `insertWith` rather than lookup followed by insertion.
    
    Reviewers: austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D3099


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

d5e9b7f5b84440e0e81515773c8fa31cbaebfd57
 compiler/simplCore/CoreMonad.hs | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/compiler/simplCore/CoreMonad.hs b/compiler/simplCore/CoreMonad.hs
index 087410c..ac3e2c4 100644
--- a/compiler/simplCore/CoreMonad.hs
+++ b/compiler/simplCore/CoreMonad.hs
@@ -83,6 +83,7 @@ import Data.Dynamic
 import Data.IORef
 import Data.Map (Map)
 import qualified Data.Map as Map
+import qualified Data.Map.Strict as MapStrict
 import Data.Word
 import Control.Monad
 import Control.Applicative ( Alternative(..) )
@@ -311,19 +312,13 @@ doSimplTick dflags tick
 doSimplTick _ _ (VerySimplCount n) = VerySimplCount (n+1)
 
 
--- Don't use Map.unionWith because that's lazy, and we want to
--- be pretty strict here!
 addTick :: TickCounts -> Tick -> TickCounts
-addTick fm tick = case Map.lookup tick fm of
-                        Nothing -> Map.insert tick 1 fm
-                        Just n  -> n1 `seq` Map.insert tick n1 fm
-                                where
-                                   n1 = n+1
-
+addTick fm tick = MapStrict.insertWith (+) tick 1 fm
 
 plusSimplCount sc1@(SimplCount { ticks = tks1, details = dts1 })
                sc2@(SimplCount { ticks = tks2, details = dts2 })
-  = log_base { ticks = tks1 + tks2, details = Map.unionWith (+) dts1 dts2 }
+  = log_base { ticks = tks1 + tks2
+             , details = MapStrict.unionWith (+) dts1 dts2 }
   where
         -- A hackish way of getting recent log info
     log_base | null (log1 sc2) = sc1    -- Nothing at all in sc2



More information about the ghc-commits mailing list