From daecfd5bd7acd95767d4d78127c1e9bbbe4463e2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 23 Apr 2013 14:30:54 -0400 Subject: [PATCH] more efficient data type for ChangeChan Making this a tset of lists of Changes, rather than a tset of Changes makes refilling it, in batch mode, much more efficient. Rather than needing to add every Change it's collected one at a time, it can add them in one fast batch operation. It would be more efficient yet to use a Set, but that would need an Eq instance for InodeCache. --- Assistant/Changes.hs | 8 ++++---- Assistant/Types/Changes.hs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Assistant/Changes.hs b/Assistant/Changes.hs index 60372f3161..05f2795d38 100644 --- a/Assistant/Changes.hs +++ b/Assistant/Changes.hs @@ -28,17 +28,17 @@ pendingAddChange f = Just <$> (PendingAddChange <$> liftIO getCurrentTime <*> pu {- Gets all unhandled changes. - Blocks until at least one change is made. -} getChanges :: Assistant [Change] -getChanges = (atomically . getTSet) <<~ changeChan +getChanges = fmap concat $ (atomically . getTSet) <<~ changeChan {- Gets all unhandled changes, without blocking. -} getAnyChanges :: Assistant [Change] -getAnyChanges = (atomically . readTSet) <<~ changeChan +getAnyChanges = fmap concat $ (atomically . readTSet) <<~ changeChan {- Puts unhandled changes back into the channel. - Note: Original order is not preserved. -} refillChanges :: [Change] -> Assistant () -refillChanges cs = (atomically . flip putTSet cs) <<~ changeChan +refillChanges cs = (atomically . flip putTSet1 cs) <<~ changeChan {- Records a change in the channel. -} recordChange :: Change -> Assistant () -recordChange c = (atomically . flip putTSet1 c) <<~ changeChan +recordChange c = (atomically . flip putTSet1 [c]) <<~ changeChan diff --git a/Assistant/Types/Changes.hs b/Assistant/Types/Changes.hs index 9729acfbdb..3b6e8501af 100644 --- a/Assistant/Types/Changes.hs +++ b/Assistant/Types/Changes.hs @@ -22,7 +22,7 @@ changeInfoKey (AddKeyChange k) = Just k changeInfoKey (LinkChange (Just k)) = Just k changeInfoKey _ = Nothing -type ChangeChan = TSet Change +type ChangeChan = TSet [Change] newChangeChan :: IO ChangeChan newChangeChan = atomically newTSet