avoid insertWith' depreaction warning
Switch to Data.Map.Strict everywhere that used it. There are still lots of lazy maps in git-annex. I think switching these is safe. The risk is that there might be a map that is used in a way that relies on the values not being evaluated to WHNF, and switching to strict might result in bad performance or memory use. So, I have not switched everything.
This commit is contained in:
parent
558a0a9328
commit
256d8f07e8
11 changed files with 24 additions and 26 deletions
8
Annex.hs
8
Annex.hs
|
@ -73,7 +73,7 @@ import "mtl" Control.Monad.Reader
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import Control.Concurrent.Async
|
import Control.Concurrent.Async
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
{- git-annex's monad is a ReaderT around an AnnexState stored in a MVar.
|
{- git-annex's monad is a ReaderT around an AnnexState stored in a MVar.
|
||||||
|
@ -262,17 +262,17 @@ withState modifier = do
|
||||||
{- Sets a flag to True -}
|
{- Sets a flag to True -}
|
||||||
setFlag :: String -> Annex ()
|
setFlag :: String -> Annex ()
|
||||||
setFlag flag = changeState $ \s ->
|
setFlag flag = changeState $ \s ->
|
||||||
s { flags = M.insertWith' const flag True $ flags s }
|
s { flags = M.insert flag True $ flags s }
|
||||||
|
|
||||||
{- Sets a field to a value -}
|
{- Sets a field to a value -}
|
||||||
setField :: String -> String -> Annex ()
|
setField :: String -> String -> Annex ()
|
||||||
setField field value = changeState $ \s ->
|
setField field value = changeState $ \s ->
|
||||||
s { fields = M.insertWith' const field value $ fields s }
|
s { fields = M.insert field value $ fields s }
|
||||||
|
|
||||||
{- Adds a cleanup action to perform. -}
|
{- Adds a cleanup action to perform. -}
|
||||||
addCleanup :: CleanupAction -> Annex () -> Annex ()
|
addCleanup :: CleanupAction -> Annex () -> Annex ()
|
||||||
addCleanup k a = changeState $ \s ->
|
addCleanup k a = changeState $ \s ->
|
||||||
s { cleanup = M.insertWith' const k a $ cleanup s }
|
s { cleanup = M.insert k a $ cleanup s }
|
||||||
|
|
||||||
{- Sets the type of output to emit. -}
|
{- Sets the type of output to emit. -}
|
||||||
setOutput :: OutputType -> Annex ()
|
setOutput :: OutputType -> Annex ()
|
||||||
|
|
|
@ -13,7 +13,7 @@ import Utility.Tense
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
{- This is as many alerts as it makes sense to display at a time.
|
{- This is as many alerts as it makes sense to display at a time.
|
||||||
- A display might be smaller, or larger, the point is to not overwhelm the
|
- A display might be smaller, or larger, the point is to not overwhelm the
|
||||||
|
@ -121,8 +121,7 @@ mergeAlert i al m = maybe updatePrune updateCombine (alertCombiner al)
|
||||||
pruneold l =
|
pruneold l =
|
||||||
let (f, rest) = partition (\(_, a) -> isFiller a) l
|
let (f, rest) = partition (\(_, a) -> isFiller a) l
|
||||||
in drop bloat f ++ rest
|
in drop bloat f ++ rest
|
||||||
updatePrune = pruneBloat $ M.filterWithKey pruneSame $
|
updatePrune = pruneBloat $ M.filterWithKey pruneSame $ M.insert i al m
|
||||||
M.insertWith' const i al m
|
|
||||||
updateCombine combiner =
|
updateCombine combiner =
|
||||||
let combined = M.mapMaybe (combiner al) m
|
let combined = M.mapMaybe (combiner al) m
|
||||||
in if M.null combined
|
in if M.null combined
|
||||||
|
|
|
@ -25,7 +25,7 @@ import Annex.Export
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import System.Posix.Types
|
import System.Posix.Types
|
||||||
import Data.Time.Clock.POSIX
|
import Data.Time.Clock.POSIX
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
getDaemonStatus :: Assistant DaemonStatus
|
getDaemonStatus :: Assistant DaemonStatus
|
||||||
|
@ -181,7 +181,7 @@ alterTransferInfo t a = updateTransferInfo' $ M.adjust a t
|
||||||
- or if already present, updates it while preserving the old transferTid,
|
- or if already present, updates it while preserving the old transferTid,
|
||||||
- transferPaused, and bytesComplete values, which are not written to disk. -}
|
- transferPaused, and bytesComplete values, which are not written to disk. -}
|
||||||
updateTransferInfo :: Transfer -> TransferInfo -> Assistant ()
|
updateTransferInfo :: Transfer -> TransferInfo -> Assistant ()
|
||||||
updateTransferInfo t info = updateTransferInfo' $ M.insertWith' merge t info
|
updateTransferInfo t info = updateTransferInfo' $ M.insertWith merge t info
|
||||||
where
|
where
|
||||||
merge new old = new
|
merge new old = new
|
||||||
{ transferTid = maybe (transferTid new) Just (transferTid old)
|
{ transferTid = maybe (transferTid new) Just (transferTid old)
|
||||||
|
|
|
@ -20,7 +20,7 @@ import Utility.NotificationBroadcaster
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import Control.Concurrent.Async
|
import Control.Concurrent.Async
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
|
|
||||||
#ifdef WITH_WEBAPP
|
#ifdef WITH_WEBAPP
|
||||||
|
@ -57,7 +57,7 @@ startNamedThread urlrenderer (NamedThread afterstartupsanitycheck name a) =
|
||||||
aid <- liftIO $ runner $ d { threadName = name }
|
aid <- liftIO $ runner $ d { threadName = name }
|
||||||
restart <- asIO $ startNamedThread urlrenderer (NamedThread False name a)
|
restart <- asIO $ startNamedThread urlrenderer (NamedThread False name a)
|
||||||
modifyDaemonStatus_ $ \s -> s
|
modifyDaemonStatus_ $ \s -> s
|
||||||
{ startedThreads = M.insertWith' const name (aid, restart) (startedThreads s) }
|
{ startedThreads = M.insert name (aid, restart) (startedThreads s) }
|
||||||
runmanaged first d = do
|
runmanaged first d = do
|
||||||
aid <- async $ runAssistant d $ do
|
aid <- async $ runAssistant d $ do
|
||||||
void first
|
void first
|
||||||
|
|
|
@ -35,7 +35,7 @@ import Annex.Wanted
|
||||||
import Utility.TList
|
import Utility.TList
|
||||||
|
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
type Reason = String
|
type Reason = String
|
||||||
|
@ -198,7 +198,7 @@ getNextTransfer acceptable = do
|
||||||
if acceptable info
|
if acceptable info
|
||||||
then do
|
then do
|
||||||
adjustTransfersSTM dstatus $
|
adjustTransfersSTM dstatus $
|
||||||
M.insertWith' const t info
|
M.insert t info
|
||||||
return $ Just r
|
return $ Just r
|
||||||
else return Nothing
|
else return Nothing
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import Git.Types
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import Control.Concurrent.Async
|
import Control.Concurrent.Async
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
data PairingWith = PairingWithSelf | PairingWithFriend
|
data PairingWith = PairingWithSelf | PairingWithFriend
|
||||||
deriving (Eq, Show, Read)
|
deriving (Eq, Show, Read)
|
||||||
|
@ -37,7 +37,7 @@ addWormholePairingState h tv = atomically $ do
|
||||||
m <- readTVar tv
|
m <- readTVar tv
|
||||||
-- use of head is safe because allids is infinite
|
-- use of head is safe because allids is infinite
|
||||||
let i = Prelude.head $ filter (`notElem` M.keys m) allids
|
let i = Prelude.head $ filter (`notElem` M.keys m) allids
|
||||||
writeTVar tv (M.insertWith' const i h m)
|
writeTVar tv (M.insert i h m)
|
||||||
return i
|
return i
|
||||||
where
|
where
|
||||||
allids = map WormholePairingId [1..]
|
allids = map WormholePairingId [1..]
|
||||||
|
|
|
@ -24,7 +24,7 @@ import Git
|
||||||
import Git.Command
|
import Git.Command
|
||||||
import qualified Git.UpdateIndex
|
import qualified Git.UpdateIndex
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
{- Queable actions that can be performed in a git repository. -}
|
{- Queable actions that can be performed in a git repository. -}
|
||||||
data Action
|
data Action
|
||||||
|
@ -117,7 +117,7 @@ updateQueue !action different sizeincrease q repo
|
||||||
, items = newitems
|
, items = newitems
|
||||||
}
|
}
|
||||||
!newsize = size q' + sizeincrease
|
!newsize = size q' + sizeincrease
|
||||||
!newitems = M.insertWith' combineNewOld (actionKey action) action (items q')
|
!newitems = M.insertWith combineNewOld (actionKey action) action (items q')
|
||||||
|
|
||||||
combineNewOld :: Action -> Action -> Action
|
combineNewOld :: Action -> Action -> Action
|
||||||
combineNewOld (CommandAction _sc1 _ps1 fs1) (CommandAction sc2 ps2 fs2) =
|
combineNewOld (CommandAction _sc1 _ps1 fs1) (CommandAction sc2 ps2 fs2) =
|
||||||
|
|
|
@ -21,7 +21,7 @@ import Common
|
||||||
import Annex.VectorClock
|
import Annex.VectorClock
|
||||||
import Logs.Line
|
import Logs.Line
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
data LogEntry v = LogEntry
|
data LogEntry v = LogEntry
|
||||||
{ changed :: VectorClock
|
{ changed :: VectorClock
|
||||||
|
@ -56,7 +56,7 @@ changeMapLog c f v = M.insert f $ LogEntry c v
|
||||||
{- Only add an LogEntry if it's newer (or at least as new as) than any
|
{- Only add an LogEntry if it's newer (or at least as new as) than any
|
||||||
- existing LogEntry for a field. -}
|
- existing LogEntry for a field. -}
|
||||||
addMapLog :: Ord f => f -> LogEntry v -> MapLog f v -> MapLog f v
|
addMapLog :: Ord f => f -> LogEntry v -> MapLog f v -> MapLog f v
|
||||||
addMapLog = M.insertWith' best
|
addMapLog = M.insertWith best
|
||||||
|
|
||||||
{- Converts a MapLog into a simple Map without the timestamp information.
|
{- Converts a MapLog into a simple Map without the timestamp information.
|
||||||
- This is a one-way trip, but useful for code that never needs to change
|
- This is a one-way trip, but useful for code that never needs to change
|
||||||
|
|
|
@ -29,7 +29,7 @@ import Logs
|
||||||
import Logs.UUIDBased
|
import Logs.UUIDBased
|
||||||
import qualified Annex.UUID
|
import qualified Annex.UUID
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
{- Records a description for a uuid in the log. -}
|
{- Records a description for a uuid in the log. -}
|
||||||
describeUUID :: UUID -> String -> Annex ()
|
describeUUID :: UUID -> String -> Annex ()
|
||||||
|
@ -79,7 +79,7 @@ uuidMapLoad :: Annex UUIDMap
|
||||||
uuidMapLoad = do
|
uuidMapLoad = do
|
||||||
m <- (simpleMap . parseLog Just) <$> Annex.Branch.get uuidLog
|
m <- (simpleMap . parseLog Just) <$> Annex.Branch.get uuidLog
|
||||||
u <- Annex.UUID.getUUID
|
u <- Annex.UUID.getUUID
|
||||||
let m' = M.insertWith' preferold u "" m
|
let m' = M.insertWith preferold u "" m
|
||||||
Annex.changeState $ \s -> s { Annex.uuidmap = Just m' }
|
Annex.changeState $ \s -> s { Annex.uuidmap = Just m' }
|
||||||
return m'
|
return m'
|
||||||
where
|
where
|
||||||
|
|
|
@ -47,7 +47,7 @@ import Utility.Aeson
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Data.HashMap.Strict as HM
|
import qualified Data.HashMap.Strict as HM
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import qualified Data.CaseInsensitive as CI
|
import qualified Data.CaseInsensitive as CI
|
||||||
|
@ -207,8 +207,7 @@ updateMetaData :: MetaField -> MetaValue -> MetaData -> MetaData
|
||||||
updateMetaData f v = updateMetaData' f (S.singleton v)
|
updateMetaData f v = updateMetaData' f (S.singleton v)
|
||||||
|
|
||||||
updateMetaData' :: MetaField -> S.Set MetaValue -> MetaData -> MetaData
|
updateMetaData' :: MetaField -> S.Set MetaValue -> MetaData -> MetaData
|
||||||
updateMetaData' f s (MetaData m) = MetaData $
|
updateMetaData' f s (MetaData m) = MetaData $ M.insertWith S.union f s m
|
||||||
M.insertWith' S.union f s m
|
|
||||||
|
|
||||||
{- New metadata overrides old._-}
|
{- New metadata overrides old._-}
|
||||||
unionMetaData :: MetaData -> MetaData -> MetaData
|
unionMetaData :: MetaData -> MetaData -> MetaData
|
||||||
|
|
|
@ -25,7 +25,7 @@ import Foreign.C.Types
|
||||||
import Foreign.C.Error
|
import Foreign.C.Error
|
||||||
import Foreign.Ptr
|
import Foreign.Ptr
|
||||||
import Foreign.Marshal
|
import Foreign.Marshal
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import qualified System.Posix.Files as Files
|
import qualified System.Posix.Files as Files
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
|
@ -212,7 +212,7 @@ handleChange kq@(Kqueue _ _ dirmap pruner) fd olddirinfo =
|
||||||
newmap' <- foldM removeSubDir newmap (map changedFile deleted)
|
newmap' <- foldM removeSubDir newmap (map changedFile deleted)
|
||||||
|
|
||||||
-- Update the cached dirinfo just looked up.
|
-- Update the cached dirinfo just looked up.
|
||||||
let newmap'' = M.insertWith' const fd newdirinfo newmap'
|
let newmap'' = M.insert fd newdirinfo newmap'
|
||||||
|
|
||||||
-- When new directories were added, need to update
|
-- When new directories were added, need to update
|
||||||
-- the kqueue to watch them.
|
-- the kqueue to watch them.
|
||||||
|
|
Loading…
Reference in a new issue