get the most commonly used commands building again

A quick benchmark of whereis shows not much speed improvement, maybe a
few percent. Profiling it found a hotspot, adds to todo.
This commit is contained in:
Joey Hess 2019-12-04 13:15:34 -04:00
parent 650a631ef8
commit b88f89c1ef
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
19 changed files with 137 additions and 108 deletions

View file

@ -6,7 +6,7 @@
-}
module Logs.Config (
ConfigName,
ConfigKey,
ConfigValue,
setGlobalConfig,
unsetGlobalConfig,
@ -18,48 +18,50 @@ import Annex.Common
import Logs
import Logs.MapLog
import qualified Annex.Branch
import Git.Types (ConfigKey(..))
import qualified Data.Map as M
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import qualified Data.Attoparsec.ByteString.Lazy as A
import Data.ByteString.Builder
type ConfigName = String
type ConfigValue = String
type ConfigValue = S.ByteString
setGlobalConfig :: ConfigName -> ConfigValue -> Annex ()
setGlobalConfig :: ConfigKey -> ConfigValue -> Annex ()
setGlobalConfig name new = do
curr <- getGlobalConfig name
when (curr /= Just new) $
setGlobalConfig' name new
setGlobalConfig' :: ConfigName -> ConfigValue -> Annex ()
setGlobalConfig' :: ConfigKey -> ConfigValue -> Annex ()
setGlobalConfig' name new = do
c <- liftIO currentVectorClock
Annex.Branch.change configLog $
buildGlobalConfig . changeMapLog c name new . parseGlobalConfig
unsetGlobalConfig :: ConfigName -> Annex ()
unsetGlobalConfig :: ConfigKey -> Annex ()
unsetGlobalConfig name = do
curr <- getGlobalConfig name
when (curr /= Nothing) $
setGlobalConfig' name "" -- set to empty string to unset
setGlobalConfig' name mempty -- set to empty string to unset
-- Reads the global config log every time.
getGlobalConfig :: ConfigName -> Annex (Maybe ConfigValue)
getGlobalConfig :: ConfigKey -> Annex (Maybe ConfigValue)
getGlobalConfig name = M.lookup name <$> loadGlobalConfig
buildGlobalConfig :: MapLog ConfigName ConfigValue -> Builder
buildGlobalConfig = buildMapLog fieldbuilder valuebuilder
buildGlobalConfig :: MapLog ConfigKey ConfigValue -> Builder
buildGlobalConfig = buildMapLog configkeybuilder valuebuilder
where
fieldbuilder = byteString . encodeBS
valuebuilder = byteString . encodeBS
configkeybuilder (ConfigKey f) = byteString f
valuebuilder = byteString
parseGlobalConfig :: L.ByteString -> MapLog ConfigName ConfigValue
parseGlobalConfig = parseMapLog string string
parseGlobalConfig :: L.ByteString -> MapLog ConfigKey ConfigValue
parseGlobalConfig = parseMapLog configkeyparser valueparser
where
string = decodeBS <$> A.takeByteString
configkeyparser = ConfigKey <$> A.takeByteString
valueparser = A.takeByteString
loadGlobalConfig :: Annex (M.Map ConfigName ConfigValue)
loadGlobalConfig = M.filter (not . null) . simpleMap . parseGlobalConfig
loadGlobalConfig :: Annex (M.Map ConfigKey ConfigValue)
loadGlobalConfig = M.filter (not . S.null) . simpleMap . parseGlobalConfig
<$> Annex.Branch.get configLog