optimisation and memory leak fix

This commit is contained in:
Joey Hess 2012-06-12 21:13:15 -04:00
parent 7d458c40db
commit da62edb42a
2 changed files with 7 additions and 7 deletions

View file

@ -34,7 +34,7 @@ data Action
{- Updating the index file, using a list of streamers that can {- Updating the index file, using a list of streamers that can
- be added to as the queue grows. -} - be added to as the queue grows. -}
= UpdateIndexAction = UpdateIndexAction
{ getStreamers :: [Git.UpdateIndex.Streamer] { getStreamers :: [Git.UpdateIndex.Streamer] -- in reverse order
} }
{- A git command to run, on a list of files that can be added to {- A git command to run, on a list of files that can be added to
- as the queue grows. -} - as the queue grows. -}
@ -104,9 +104,8 @@ addUpdateIndex streamer q repo =
updateQueue action different 1 q repo updateQueue action different 1 q repo
where where
key = actionKey action key = actionKey action
-- streamer is added to the end of the list, since -- the list is built in reverse order
-- order does matter for update-index input action = UpdateIndexAction $ streamer : streamers
action = UpdateIndexAction $ streamers ++ [streamer]
streamers = maybe [] getStreamers $ M.lookup key $ items q streamers = maybe [] getStreamers $ M.lookup key $ items q
different (UpdateIndexAction _) = False different (UpdateIndexAction _) = False
@ -116,7 +115,7 @@ addUpdateIndex streamer q repo =
- different action, it will be flushed; this is to ensure that conflicting - different action, it will be flushed; this is to ensure that conflicting
- actions, like add and rm, are run in the right order.-} - actions, like add and rm, are run in the right order.-}
updateQueue :: Action -> (Action -> Bool) -> Int -> Queue -> Repo -> IO Queue updateQueue :: Action -> (Action -> Bool) -> Int -> Queue -> Repo -> IO Queue
updateQueue action different sizeincrease q repo updateQueue !action different sizeincrease q repo
| null (filter different (M.elems (items q))) = return $ go q | null (filter different (M.elems (items q))) = return $ go q
| otherwise = go <$> flush q repo | otherwise = go <$> flush q repo
where where
@ -147,7 +146,8 @@ flush (Queue _ lim m) repo = do
- this allows queueing commands that do not need a list of files. -} - this allows queueing commands that do not need a list of files. -}
runAction :: Repo -> Action -> IO () runAction :: Repo -> Action -> IO ()
runAction repo (UpdateIndexAction streamers) = runAction repo (UpdateIndexAction streamers) =
Git.UpdateIndex.streamUpdateIndex repo streamers -- list is stored in reverse order
Git.UpdateIndex.streamUpdateIndex repo $ reverse streamers
runAction repo action@(CommandAction {}) = runAction repo action@(CommandAction {}) =
pOpen WriteToPipe "xargs" ("-0":"git":params) feedxargs pOpen WriteToPipe "xargs" ("-0":"git":params) feedxargs
where where

View file

@ -71,7 +71,7 @@ unstageFile file repo = do
{- A streamer that adds a symlink to the index. -} {- A streamer that adds a symlink to the index. -}
stageSymlink :: FilePath -> Sha -> Repo -> IO Streamer stageSymlink :: FilePath -> Sha -> Repo -> IO Streamer
stageSymlink file sha repo = do stageSymlink file sha repo = do
line <- updateIndexLine !line <- updateIndexLine
<$> pure sha <$> pure sha
<*> pure SymlinkBlob <*> pure SymlinkBlob
<*> toTopFilePath file repo <*> toTopFilePath file repo