[commit: base] : Minor refactoring to simplify unregisterFd_ in Manager. (88866f4)

Johan Tibell johan.tibell at gmail.com
Tue Feb 12 07:50:31 CET 2013


Repository : ssh://darcs.haskell.org//srv/darcs/packages/base

On branch  : 

http://hackage.haskell.org/trac/ghc/changeset/88866f4b4cf63bc14040dc8ca1d743904207ddc4

>---------------------------------------------------------------

commit 88866f4b4cf63bc14040dc8ca1d743904207ddc4
Author: Andreas Voellmy <andreas.voellmy at gmail.com>
Date:   Fri Dec 21 13:08:09 2012 -0500

    Minor refactoring to simplify unregisterFd_ in Manager.

>---------------------------------------------------------------

 GHC/Event/Manager.hs |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/GHC/Event/Manager.hs b/GHC/Event/Manager.hs
index c977abd..0148d79 100644
--- a/GHC/Event/Manager.hs
+++ b/GHC/Event/Manager.hs
@@ -279,9 +279,7 @@ pairEvents prev m fd = let l = eventsOf prev
 unregisterFd_ :: EventManager -> FdKey -> IO Bool
 unregisterFd_ mgr@(EventManager{..}) (FdKey fd u) =
   modifyMVar (callbackTableVar mgr fd) $ \oldMap -> do
-    let dropReg cbs = case filter ((/= u) . keyUnique . fdKey) cbs of
-                          []   -> Nothing
-                          cbs' -> Just cbs'
+    let dropReg = nullToNothing . filter ((/= u) . keyUnique . fdKey) 
         fd' = fromIntegral fd
         (!newMap, (oldEvs, newEvs)) =
             case IM.updateWith dropReg fd' oldMap of
@@ -332,3 +330,7 @@ onFdEvent mgr fd evs = do
       Just cbs -> forM_ cbs $ \(FdData reg ev cb) ->
                     when (evs `I.eventIs` ev) $ cb reg evs
       Nothing  -> return ()
+
+nullToNothing :: [a] -> Maybe [a]
+nullToNothing []       = Nothing
+nullToNothing xs@(_:_) = Just xs





More information about the ghc-commits mailing list