[Pkg-haskell-commits] [package-plan] 04/05: Switch to ByteString and attoparsec
Joachim Breitner
nomeata at moszumanska.debian.org
Sat May 31 21:35:03 UTC 2014
This is an automated email from the git hooks/post-receive script.
nomeata pushed a commit to branch master
in repository package-plan.
commit 766d488430badc36f4d9631d94d14777b9fa0a61
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Sat May 31 23:31:02 2014 +0200
Switch to ByteString and attoparsec
instead of String and parsec. Half the memory cost (but speed the same,
as limited by cabal list -- maybe I should read the tarfile after all).
---
update-suggestions.hs | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/update-suggestions.hs b/update-suggestions.hs
index 26506a6..5d3bbdf 100644
--- a/update-suggestions.hs
+++ b/update-suggestions.hs
@@ -7,46 +7,51 @@ minor upgrades (first three components of the version identical).
-}
import qualified Data.Map as M
-import Text.Parsec
-import Text.Parsec.String
import Control.Monad
import Data.List
import Data.Functor
-import System.Process
+import System.Process.ByteString
import Text.Printf
+import qualified Data.ByteString.Char8 as BS
+import Data.Attoparsec.ByteString.Char8 hiding (take)
+import Control.Applicative
-type Package = String
+type Package = BS.ByteString
type Version = [Integer]
readCabalVersions :: IO (M.Map Package [Version])
readCabalVersions = do
- raw <- readProcess "cabal" ["list", "--simple-output"] ""
+ (_, raw, _) <- readProcessWithExitCode "cabal" ["list", "--simple-output"] BS.empty
return $
M.fromListWith (++) $
map (\(p,v) -> (p,[v])) $
- either (error.show) id $
- parse packagePlanParser "cabal list" raw
+ either (error) id $
+ parseOnly packagePlanParser raw
readPackagePlan :: IO (M.Map Package Version)
readPackagePlan = do
- raw <- readFile "packages.txt"
- return $ M.fromList $ either (error.show) id $ parse packagePlanParser "packages.txt" raw
+ raw <- BS.readFile "packages.txt"
+ return $
+ M.fromList $
+ either (error) id $
+ parseOnly packagePlanParser raw
packagePlanParser :: Parser [(Package, Version)]
-packagePlanParser = between (return ()) eof $ line `sepEndBy` newline
+packagePlanParser = do
+ many' line <* endOfInput
where
line = do
p <- packageName
char ' '
v <- versionNumber
- manyTill anyChar (lookAhead newline)
+ manyTill anyChar endOfLine
return (p,v)
packageName :: Parser Package
-packageName = many (alphaNum <|> char '-')
+packageName = takeWhile1 (inClass "a-zA-Z0-9-")
versionNumber :: Parser Version
-versionNumber = (read <$> many1 digit) `sepBy` char '.'
+versionNumber = decimal `sepBy` char '.'
showVersionNumber :: Version -> String
showVersionNumber = concat . intersperse "." . map show
@@ -57,7 +62,7 @@ candidate p v = take 3 p == take 3 v && v > p
hdiffLink :: Package -> Version -> Version -> String
hdiffLink p v1 v2 =
printf "http://hdiff.luite.com/cgit/%s/diff/?id=%s&id2=%s"
- p (showVersionNumber v2) (showVersionNumber v1)
+ (BS.unpack p) (showVersionNumber v2) (showVersionNumber v1)
main :: IO ()
main = do
@@ -70,7 +75,7 @@ main = do
Just better -> do
let best = maximum better
putStrLn $ printf "%s %s -> %s (%s)"
- pkg
+ (BS.unpack pkg)
(showVersionNumber plan)
(showVersionNumber best)
(hdiffLink pkg plan best)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-haskell/package-plan.git
More information about the Pkg-haskell-commits
mailing list