diff options
author | 2011-01-30 01:41:15 -0400 | |
---|---|---|
committer | 2011-01-30 01:41:15 -0400 | |
commit | 96e561bc477bd0a4bbffb769369fabe1e1e1982f (patch) | |
tree | 53de4543abb557e5ed49f8d353e1f6ceb7eec006 /Command/Unused.hs | |
parent | 53677d764710d522394f59e494fb6b632aca2326 (diff) |
use Set instead of existence Map
more efficient and idiomatic
I did try using Set.difference, it's still slower than my method.
Diffstat (limited to 'Command/Unused.hs')
-rw-r--r-- | Command/Unused.hs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/Command/Unused.hs b/Command/Unused.hs index 32d70aa19..28a26f82c 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -9,7 +9,7 @@ module Command.Unused where import Control.Monad (filterM, unless) import Control.Monad.State (liftIO) -import qualified Data.Map as M +import qualified Data.Set as S import Data.Maybe import System.FilePath import System.Directory @@ -99,16 +99,12 @@ calcUnusedKeys present referenced tmps = (unused, staletmp, duptmp) staletmp = tmps `exclude` present duptmp = tmps `exclude` staletmp - -- Constructing a single map, of the set that tends to be + -- Constructing a single set, of the list that tends to be -- smaller, appears more efficient in both memory and CPU - -- than constructing and taking the M.difference of two maps. + -- than constructing and taking the S.difference of two sets. exclude [] _ = [] -- optimisation - exclude smaller larger = M.keys $ remove larger $ existsMap smaller - - existsMap :: Ord k => [k] -> M.Map k Int - existsMap l = M.fromList $ map (\k -> (k, 1)) l - - remove a b = foldl (flip M.delete) b a + exclude smaller larger = S.toList $ remove larger $ S.fromList smaller + remove a b = foldl (flip S.delete) b a {- List of keys referenced by symlinks in the git repo. -} getKeysReferenced :: Annex [Key] |