From c0ad47c05c3c294e5c388bea580d33ab6791dab2 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Tue, 23 Jan 2024 11:14:50 -0500 Subject: [PATCH] Go for minimal diff --- precompute-fileinfo/src/Main.hs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/precompute-fileinfo/src/Main.hs b/precompute-fileinfo/src/Main.hs index a9b4c73a..0b6daedc 100644 --- a/precompute-fileinfo/src/Main.hs +++ b/precompute-fileinfo/src/Main.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE ScopedTypeVariables #-} - module Main where import Control.Concurrent @@ -169,17 +167,14 @@ writeMap fp hashes = withFile fp WriteMode $ \h -> readMap :: FilePath -> IO (Map MD5 (SHA256, Length)) readMap fp = withFile fp ReadMode $ \h -> do - hashes <- mapFromParseEntry . lines <$> hGetContents h + hashes <- Map.fromList . map parseEntry . lines <$> hGetContents h evaluate $ rnf hashes return hashes where - mapFromParseEntry :: [String] -> Map MD5 (SHA256, Length) - mapFromParseEntry mapLines = Map.fromList - [ case ws of - [md5, sha256, len] -> (md5, (sha256, read len)) - _ -> (unwords ws, undefined) - | ws <- words <$> mapLines - ] + parseEntry :: String -> (MD5, (SHA256, Length)) + parseEntry line = case words line of + [md5, sha256, len] -> (md5, (sha256, read len)) + _ -> error $ "failed: parseEntry " ++ show line {------------------------------------------------------------------------------- Auxiliary