diff options
author | Joey Hess <joeyh@joeyh.name> | 2019-01-09 15:00:43 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2019-01-09 15:05:49 -0400 |
commit | 6f66b53a30219eea05870bfa86b0c48ccb56145c (patch) | |
tree | 5a7b72d2ad076b5badcbe2ed334ab71644266037 /Logs | |
parent | 3f7fe1d32598e9feaccbe6745c23fc5a7ce45e2b (diff) |
newtype Group to ByteString
This may speed up queries for things in groups, due to Eq and Ord being faster.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/Group.hs | 14 | ||||
-rw-r--r-- | Logs/PreferredContent/Raw.hs | 10 |
2 files changed, 14 insertions, 10 deletions
diff --git a/Logs/Group.hs b/Logs/Group.hs index 7df9c86217..1dcc84247e 100644 --- a/Logs/Group.hs +++ b/Logs/Group.hs @@ -16,6 +16,7 @@ module Logs.Group ( inUnwantedGroup ) where +import qualified Data.ByteString.Lazy as L import qualified Data.Map as M import qualified Data.Set as S import Data.ByteString.Builder @@ -38,9 +39,7 @@ groupChange uuid@(UUID _) modifier = do curr <- lookupGroups uuid c <- liftIO currentVectorClock Annex.Branch.change groupLog $ - buildLog buildGroup . - changeLog c uuid (modifier curr) . - parseLog (Just . S.fromList . words) . decodeBL + buildLog buildGroup . changeLog c uuid (modifier curr) . parseGroup -- The changed group invalidates the preferred content cache. Annex.changeState $ \s -> s @@ -54,7 +53,10 @@ buildGroup = go . S.toList where go [] = mempty go (g:gs) = bld g <> mconcat [ charUtf8 ' ' <> bld g' | g' <- gs ] - bld = byteString . encodeBS + bld (Group g) = byteString g + +parseGroup :: L.ByteString -> Log (S.Set Group) +parseGroup = parseLog (Just . S.fromList . map toGroup . words) . decodeBL groupSet :: UUID -> S.Set Group -> Annex () groupSet u g = groupChange u (const g) @@ -66,9 +68,7 @@ groupMap = maybe groupMapLoad return =<< Annex.getState Annex.groupmap {- Loads the map, updating the cache. -} groupMapLoad :: Annex GroupMap groupMapLoad = do - m <- makeGroupMap . simpleMap . - parseLog (Just . S.fromList . words) . decodeBL <$> - Annex.Branch.get groupLog + m <- makeGroupMap . simpleMap . parseGroup <$> Annex.Branch.get groupLog Annex.changeState $ \s -> s { Annex.groupmap = Just m } return m diff --git a/Logs/PreferredContent/Raw.hs b/Logs/PreferredContent/Raw.hs index d4dde50ab2..b095428461 100644 --- a/Logs/PreferredContent/Raw.hs +++ b/Logs/PreferredContent/Raw.hs @@ -17,6 +17,7 @@ import Types.StandardGroups import Types.Group import qualified Data.Map as M +import qualified Data.ByteString.Lazy as L import Data.ByteString.Builder {- Changes the preferred content configuration of a remote. -} @@ -46,13 +47,16 @@ groupPreferredContentSet g val = do Annex.Branch.change groupPreferredContentLog $ buildGroupPreferredContent . changeMapLog c g val - . parseMapLog Just Just . decodeBL + . parseGroupPreferredContent Annex.changeState $ \s -> s { Annex.preferredcontentmap = Nothing } +parseGroupPreferredContent :: L.ByteString -> MapLog Group String +parseGroupPreferredContent = parseMapLog (Just . toGroup) Just . decodeBL + buildGroupPreferredContent :: MapLog Group PreferredContentExpression -> Builder buildGroupPreferredContent = buildMapLog buildgroup buildexpr where - buildgroup = byteString . encodeBS + buildgroup (Group g) = byteString g buildexpr = byteString . encodeBS preferredContentMapRaw :: Annex (M.Map UUID PreferredContentExpression) @@ -64,5 +68,5 @@ requiredContentMapRaw = simpleMap . parseLog Just . decodeBL <$> Annex.Branch.get requiredContentLog groupPreferredContentMapRaw :: Annex (M.Map Group PreferredContentExpression) -groupPreferredContentMapRaw = simpleMap . parseMapLog Just Just . decodeBL +groupPreferredContentMapRaw = simpleMap . parseGroupPreferredContent <$> Annex.Branch.get groupPreferredContentLog |