summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Feuer <david.feuer@gmail.com>2017-02-07 21:34:00 -0500
committerDavid Feuer <David.Feuer@gmail.com>2017-02-07 21:34:01 -0500
commitd5e9b7f5b84440e0e81515773c8fa31cbaebfd57 (patch)
tree6a9a400073e302aca05b0c57d70566c35629a436
parent5ce39f6395efd81f9cc0e0aa2f36a7552ed75f7c (diff)
downloadhaskell-d5e9b7f5b84440e0e81515773c8fa31cbaebfd57.tar.gz
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
-rw-r--r--compiler/simplCore/CoreMonad.hs13
1 files changed, 4 insertions, 9 deletions
diff --git a/compiler/simplCore/CoreMonad.hs b/compiler/simplCore/CoreMonad.hs
index 087410c3bf..ac3e2c4fb9 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