From 6931eec3ce4203a882fba0649c9f0abc2248a683 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 9 Jan 2021 18:59:10 -0800 Subject: [PATCH] ;check: uniqueleafnames: short circuit to avoid wasted work --- hledger/Hledger/Cli/Commands/Check/Uniqueleafnames.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Check/Uniqueleafnames.hs b/hledger/Hledger/Cli/Commands/Check/Uniqueleafnames.hs index 5d247738b..0fa4da809 100755 --- a/hledger/Hledger/Cli/Commands/Check/Uniqueleafnames.hs +++ b/hledger/Hledger/Cli/Commands/Check/Uniqueleafnames.hs @@ -23,9 +23,11 @@ import Text.Printf (printf) journalCheckUniqueleafnames :: Journal -> Either String () journalCheckUniqueleafnames j = do -- find all duplicate leafnames, and the full account names they appear in - let dupes = finddupes $ journalLeafAndFullAccountNames j - -- report the first posting that references one of them (and its position), for now - sequence_ $ map (checkposting dupes) $ journalPostings j + case finddupes $ journalLeafAndFullAccountNames j of + [] -> Right () + dupes -> + -- report the first posting that references one of them (and its position), for now + sequence_ $ map (checkposting dupes) $ journalPostings j finddupes :: (Ord leaf, Eq full) => [(leaf, full)] -> [(leaf, [full])] finddupes leafandfullnames = zip dupLeafs dupAccountNames