diff options
author | Joey Hess <joey@kitenet.net> | 2014-07-27 12:24:12 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-07-27 12:24:12 -0400 |
commit | c7f90efb8626573f2e2927195ce16cb609fac315 (patch) | |
tree | d52526e3fe4dfae370d158b3fd9617f3d69a67f3 /Backend.hs | |
parent | 9e3753eb3a51147c65b3048e6197227093098de6 (diff) |
use map for faster backend name lookup
Diffstat (limited to 'Backend.hs')
-rw-r--r-- | Backend.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Backend.hs b/Backend.hs index dded0d005..245e79ec2 100644 --- a/Backend.hs +++ b/Backend.hs @@ -32,6 +32,8 @@ import qualified Backend.Hash import qualified Backend.WORM import qualified Backend.URL +import qualified Data.Map as M + list :: [Backend] list = Backend.Hash.backends ++ Backend.WORM.backends ++ Backend.URL.backends @@ -116,7 +118,9 @@ lookupBackendName :: String -> Backend lookupBackendName s = fromMaybe unknown $ maybeLookupBackendName s where unknown = error $ "unknown backend " ++ s + maybeLookupBackendName :: String -> Maybe Backend -maybeLookupBackendName s = headMaybe matches - where - matches = filter (\b -> s == B.name b) list +maybeLookupBackendName s = M.lookup s nameMap + +nameMap :: M.Map String Backend +nameMap = M.fromList $ zip (map B.name list) list |