[commit: ghc] master: Avoid repeated list elem checks (7938ef2)

git at git.haskell.org git at git.haskell.org
Sun Feb 12 01:09:04 UTC 2017


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

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

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

commit 7938ef23387e10ea8e33fc6531706b79c62634af
Author: David Feuer <david.feuer at gmail.com>
Date:   Sat Feb 11 19:23:20 2017 -0500

    Avoid repeated list elem checks
    
    Convert a list to a set before testing membership multiple times.
    
    Reviewers: austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3111


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

7938ef23387e10ea8e33fc6531706b79c62634af
 compiler/main/SysTools.hs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 17ce634..b34b1b8 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -79,6 +79,7 @@ import System.Directory
 import Data.Char
 import Data.List
 import qualified Data.Map as Map
+import qualified Data.Set as Set
 
 #ifndef mingw32_HOST_OS
 import qualified System.Posix.Internals
@@ -1068,9 +1069,11 @@ cleanTempFilesExcept dflags dont_delete
    $ mask_
    $ do let ref = filesToClean dflags
         to_delete <- atomicModifyIORef' ref $ \files ->
-            let (to_keep,to_delete) = partition (`elem` dont_delete) files
-            in  (to_keep,to_delete)
+            let res@(_to_keep, _to_delete) =
+                    partition (`Set.member` dont_delete_set) files
+            in  res
         removeTmpFiles dflags to_delete
+  where dont_delete_set = Set.fromList dont_delete
 
 
 -- Return a unique numeric temp file suffix



More information about the ghc-commits mailing list