avoid unnecessary building of a one-off Map

A case lookup should be more efficient.
This commit is contained in:
Joey Hess 2016-02-03 12:59:28 -04:00
parent 199c4f9508
commit aded00c5f0
Failed to extract signature

View file

@ -74,26 +74,26 @@ exprParser matchstandard matchgroupwanted getgroupmap configmap mu expr =
parseToken :: FileMatcher Annex -> FileMatcher Annex -> MkLimit Annex -> MkLimit Annex -> Annex GroupMap -> String -> Either String (Token (MatchFiles Annex)) parseToken :: FileMatcher Annex -> FileMatcher Annex -> MkLimit Annex -> MkLimit Annex -> Annex GroupMap -> String -> Either String (Token (MatchFiles Annex))
parseToken matchstandard matchgroupwanted checkpresent checkpreferreddir getgroupmap t parseToken matchstandard matchgroupwanted checkpresent checkpreferreddir getgroupmap t
| t `elem` tokens = Right $ token t | t `elem` tokens = Right $ token t
| t == "standard" = call matchstandard | otherwise = case t of
| t == "groupwanted" = call matchgroupwanted "standard" -> call matchstandard
| t == "present" = use checkpresent "groupwanted" -> call matchgroupwanted
| t == "inpreferreddir" = use checkpreferreddir "present" -> use checkpresent
| t == "unused" = Right $ Operation limitUnused "inpreferreddir" -> use checkpreferreddir
| t == "anything" = Right $ Operation limitAnything "unused" -> Right $ Operation limitUnused
| t == "nothing" = Right $ Operation limitNothing "anything" -> Right $ Operation limitAnything
| otherwise = maybe (Left $ "near " ++ show t) use $ M.lookup k $ "nothing" -> Right $ Operation limitNothing
M.fromList _ -> case k of
[ ("include", limitInclude) "include" -> use limitInclude
, ("exclude", limitExclude) "exclude" -> use limitExclude
, ("copies", limitCopies) "copies" -> use limitCopies
, ("lackingcopies", limitLackingCopies False) "lackingcopies" -> use $ limitLackingCopies False
, ("approxlackingcopies", limitLackingCopies True) "approxlackingcopies" -> use $ limitLackingCopies True
, ("inbackend", limitInBackend) "inbackend" -> use limitInBackend
, ("largerthan", limitSize (>)) "largerthan" -> use $ limitSize (>)
, ("smallerthan", limitSize (<)) "smallerthan" -> use $ limitSize (<)
, ("metadata", limitMetaData) "metadata" -> use limitMetaData
, ("inallgroup", limitInAllGroup getgroupmap) "inallgroup" -> use $ limitInAllGroup getgroupmap
] _ -> Left $ "near " ++ show t
where where
(k, v) = separate (== '=') t (k, v) = separate (== '=') t
use a = Operation <$> a v use a = Operation <$> a v