[commit: ghc] master: HscTypes: Use foldl' instead of foldr (2cc67ad)

git at git.haskell.org git at git.haskell.org
Tue Jan 24 21:07:58 UTC 2017


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

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

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

commit 2cc67adb29b33e15727c6463ed84e43cc159b3a2
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Tue Jan 24 12:52:06 2017 -0500

    HscTypes: Use foldl' instead of foldr
    
    In this case we are building a map, for which `foldl'` is much better
    suited. This has a small but consistent impact on compiler allocations,
    ```
            -1 s.d.                -----          -0.161%
            +1 s.d.                -----          -0.011%
            Average                -----          -0.086%
    ```
    
    Test Plan: Validate
    
    Reviewers: austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2967


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

2cc67adb29b33e15727c6463ed84e43cc159b3a2
 compiler/main/HscTypes.hs | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs
index 8e6925f..51cec26 100644
--- a/compiler/main/HscTypes.hs
+++ b/compiler/main/HscTypes.hs
@@ -194,6 +194,7 @@ import GHC.Serialized   ( Serialized )
 
 import Foreign
 import Control.Monad    ( guard, liftM, when, ap )
+import Data.Foldable    ( foldl' )
 import Data.IORef
 import Data.Time
 import Exception
@@ -1124,10 +1125,10 @@ mkIfaceHashCache :: [(Fingerprint,IfaceDecl)]
 mkIfaceHashCache pairs
   = \occ -> lookupOccEnv env occ
   where
-    env = foldr add_decl emptyOccEnv pairs
-    add_decl (v,d) env0 = foldr add env0 (ifaceDeclFingerprints v d)
+    env = foldl' add_decl emptyOccEnv pairs
+    add_decl env0 (v,d) = foldl' add env0 (ifaceDeclFingerprints v d)
       where
-        add (occ,hash) env0 = extendOccEnv env0 occ (occ,hash)
+        add env0 (occ,hash) = extendOccEnv env0 occ (occ,hash)
 
 emptyIfaceHashCache :: OccName -> Maybe (OccName, Fingerprint)
 emptyIfaceHashCache _occ = Nothing



More information about the ghc-commits mailing list