optimise getUUID

This avoids a Map lookup each time it's called, instead the GitConfig field
lazily looks it up once and then caches.
This commit is contained in:
Joey Hess 2016-01-20 16:55:06 -04:00
parent 737e45156e
commit 23ff58cd4f
Failed to extract signature
2 changed files with 14 additions and 5 deletions

View file

@ -19,6 +19,7 @@ import qualified Git.Construct
import Git.SharedRepository
import Utility.DataUnits
import Config.Cost
import Types.UUID
import Types.Distribution
import Types.Availability
import Types.NumCopies
@ -32,6 +33,7 @@ import Utility.ThreadScheduler (Seconds(..))
- such as annex.foo -}
data GitConfig = GitConfig
{ annexVersion :: Maybe String
, annexUUID :: UUID
, annexNumCopies :: Maybe NumCopies
, annexDiskReserve :: Integer
, annexDirect :: Bool
@ -75,6 +77,7 @@ data GitConfig = GitConfig
extractGitConfig :: Git.Repo -> GitConfig
extractGitConfig r = GitConfig
{ annexVersion = notempty $ getmaybe (annex "version")
, annexUUID = maybe NoUUID toUUID $ getmaybe (annex "uuid")
, annexNumCopies = NumCopies <$> getmayberead (annex "numcopies")
, annexDiskReserve = fromMaybe onemegabyte $
readSize dataUnits =<< getmaybe (annex "diskreserve")