git.iko.soy/typeable/cabal2nix
on master help sign in
Hackage4Nix: replaced use of ByteString with String to simply the code

It turned out that ByteStrings affected the performance pretty much zilch.

commit4c9c819f816c3f39ede173c50a34892a0b844264 authorPeter Simons <simons@cryp.to> dateSun 14 Aug 2011, 00:31 (15 years ago) parente6aca8c
2 files changed+22−31
cabal2nix.cabal+1−1 src/Hackage4Nix.hs+21−30
cabal2nix.cabal+1−1
@@ -56,7 +56,7 @@ Executable cabal2nix
5656Executable hackage4nix
5757 main-is: Hackage4Nix.hs
5858 hs-source-dirs: src
59− Build-Depends: base >= 3 && < 5, Cabal >= 1.8, pretty, filepath, directory, bytestring,
59+ Build-Depends: base >= 3 && < 5, Cabal >= 1.8, pretty, filepath, directory,
6060 regex-posix, mtl, containers
6161 Extensions: PatternGuards
6262 other-modules: Cabal2Nix.Pretty
src/Hackage4Nix.hs+21−30
@@ -11,7 +11,6 @@ import Data.List
1111import qualified Data.Set as Set
1212import Control.Monad.State
1313import Control.Exception ( bracket )
14−import qualified Data.ByteString.Char8 as BS
1514import Text.Regex.Posix
1615import Data.Version
1716import Text.ParserCombinators.ReadP ( readP_to_S )
@@ -22,14 +21,6 @@ import Cabal2Nix.Package ( cabal2nix, showNixPkg, PkgName, PkgSHA256, PkgPlatfor
2221 , PkgNoHaddock )
2322import qualified Cabal2Nix.Package ( Pkg(..) )
2423
25−type ByteString = BS.ByteString
26−
27−pack :: String -> ByteString
28−pack = BS.pack
29−
30−unpack :: ByteString -> String
31−unpack = BS.unpack
32−
3324type PkgSet = Set.Set Pkg
3425
3526data Configuration = Configuration
@@ -89,49 +80,49 @@ type PkgVersion = String
8980data Pkg = Pkg PkgName PkgVersion PkgSHA256 PkgNoHaddock PkgPlatforms PkgMaintainers FilePath
9081 deriving (Show, Eq, Ord)
9182
92−regmatch :: ByteString -> String -> Bool
93−regmatch buf patt = match (makeRegexOpts compExtended execBlank (pack patt)) buf
83+regmatch :: String -> String -> Bool
84+regmatch buf patt = match (makeRegexOpts compExtended execBlank patt) buf
9485
95−regsubmatch :: ByteString -> String -> [ByteString]
86+regsubmatch :: String -> String -> [String]
9687regsubmatch buf patt = let (_,_,_,x) = f in x
97− where f :: (ByteString,ByteString,ByteString,[ByteString])
98− f = match (makeRegexOpts compExtended execBlank (pack patt)) buf
88+ where f :: (String,String,String,[String])
89+ f = match (makeRegexOpts compExtended execBlank patt) buf
9990
10091normalizeMaintainer :: String -> String
10192normalizeMaintainer x
10293 | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x
10394 | otherwise = x
10495
105−parseNixFile :: FilePath -> ByteString -> Hackage4Nix (Maybe Pkg)
96+parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
10697parseNixFile path buf
10798 | not (buf `regmatch` "cabal.mkDerivation")
10899 = msgDebug ("ignore non-cabal package " ++ path) >> return Nothing
109− | True <- (pack path) `regmatch` (concat (intersperse "|" badPackages))
100+ | True <- path `regmatch` (concat (intersperse "|" badPackages))
110101 = msgDebug ("ignore known bad package " ++ path) >> return Nothing
111102 | True <- buf `regmatch` "src = (fetchgit|sourceFromHead)"
112103 = msgDebug ("ignore non-hackage package " ++ path) >> return Nothing
113104 | buf `regmatch` "preConfigure|configureFlags|postInstall|patchPhase"
114105 = msgInfo ("ignore patched package " ++ path) >> return Nothing
115− | True <- buf =~ pack "cabal.mkDerivation"
106+ | True <- buf =~ "cabal.mkDerivation"
116107 , [name] <- buf `regsubmatch` "name *= *\"([^\"]+)\""
117108 , [vers] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
118109 , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
119110 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
120111 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
121112 , haddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
122− = let plats' = concatMap BS.words (map (BS.map (\c -> if c == '+' then ' ' else c)) plats)
123− maint' = concatMap BS.words maint
113+ = let plats' = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
114+ maint' = concatMap words maint
124115 noHaddock
125− | b:[] <- haddock, unpack b == "true" = True
126− | otherwise = False
116+ | "true":[] <- haddock = True
117+ | otherwise = False
127118 in
128− return $ Just $ Pkg (unpack name)
129− (unpack vers)
130− (unpack sha)
119+ return $ Just $ Pkg name
120+ vers
121+ sha
131122 noHaddock
132− (map unpack plats')
133− (map (normalizeMaintainer . unpack) maint')
134− (path)
123+ plats'
124+ (map normalizeMaintainer maint')
125+ path
135126 | True <- buf `regmatch` "cabal.mkDerivation"
136127 = msgInfo ("failed to parse file " ++ path) >> return Nothing
137128 | otherwise = return Nothing
@@ -163,7 +154,7 @@ updateNixPkgs paths = do
163154 msgDebug $ "updating = " ++ show paths
164155 flip mapM_ paths $ \fileOrDir ->
165156 flip discoverNixFiles fileOrDir $ \file -> do
166− nix' <- io (BS.readFile file) >>= parseNixFile file
157+ nix' <- io (readFile file) >>= parseNixFile file
167158 flip (maybe (return ())) nix' $ \nix -> do
168159 let Pkg name vers sha noHaddock plats maints path = nix
169160 maints' = nub (sort (maints ++ ["andres","simons"]))
@@ -201,8 +192,8 @@ genCabal2NixCmdline (Pkg name vers _ noHaddock plats maints path) = unwords $ ["
201192 | ["self.ghc.meta.platforms"] == plats = []
202193 | otherwise = [ "--platform=" ++ p | p <- plats ]
203194 path'
204− | pack path `regmatch` "/[0-9\\.]+\\.nix$" = replaceFileName path (vers <.> "nix")
205− | otherwise = path
195+ | path `regmatch` "/[0-9\\.]+\\.nix$" = replaceFileName path (vers <.> "nix")
196+ | otherwise = path
206197
207198data CliOption = PrintHelp | Verbose | HackageDB FilePath
208199 deriving (Eq)