From 2169c1b1dea4391366e07d18a3743748ff94fe9e Mon Sep 17 00:00:00 2001
From: Jose A Ortega Ruiz <jao@gnu.org>
Date: Fri, 12 Feb 2010 00:58:21 +0100
Subject: Cosmetics

Ignore-this: eb0c478fb8547f3cd20ded3cd195b06c

darcs-hash:20100211235821-748be-dee59b89551e86363cdd42f2de229ace35f5437b.gz
---
 Plugins/Monitors/Top.hs | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/Plugins/Monitors/Top.hs b/Plugins/Monitors/Top.hs
index 14ccf1e..a0b3fb7 100644
--- a/Plugins/Monitors/Top.hs
+++ b/Plugins/Monitors/Top.hs
@@ -12,7 +12,7 @@
 --
 -----------------------------------------------------------------------------
 
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, BangPatterns #-}
 
 module Plugins.Monitors.Top (startTopCpu, topMemConfig, runTopMem) where
 
@@ -131,21 +131,19 @@ type TIVar = MVar Times
 
 topTimeProcesses :: Int -> TIVar -> Float -> IO [Timeinfo]
 topTimeProcesses n tivar lapse = do
-  t0 <- readMVar tivar
-  t1 <- timeinfos
-  modifyMVar_ tivar (\_ -> return $! t1)
-  let ts = M.elems $ combineTimeInfos t0 t1
-      sts = take n $ sortBy cmp ts
-      cmp (TI _ x) (TI _ y) = compare y x
-      norm (TI nm t) = TI nm (100 * t / lapse)
-  return $! map norm sts
+  modifyMVar tivar $ \t0 ->
+    timeinfos >>= (\(!t1) -> let ts = M.elems $ combineTimeInfos t0 t1
+                                 sts = take n $ sortBy cmp ts
+                                 cmp (TI _ x) (TI _ y) = compare y x
+                                 norm (TI nm t) = TI nm (100 * t / lapse)
+                             in return $! (t1, map norm sts))
 
 showTimeInfo :: Timeinfo -> Monitor [String]
 showTimeInfo (TI n t) = showInfo n (showDigits 1 t) t
 
 runTopCpu :: TIVar -> Float -> [String] -> Monitor String
 runTopCpu tivar lapse _ = do
-   ps <- io $ topTimeProcesses maxProc tivar lapse
+   ps <- io $! topTimeProcesses maxProc tivar lapse
    pstr <- mapM showTimeInfo ps
    parseTemplate $ concat pstr
 
-- 
cgit v1.2.3