summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorSibi Prabakaran <sibi@psibi.in>2020-06-13 17:33:12 +0530
committerjao <jao@gnu.org>2020-06-23 16:38:20 +0100
commit2b13b5cf6595d81280c95eb9cf507a9817e3f641 (patch)
tree8d2413c94defe00d3b1cf6c595793e9605daed35 /src
parentfc70c4f16a0e2c3f209c074d60ef98c1300ef28f (diff)
downloadxmobar-2b13b5cf6595d81280c95eb9cf507a9817e3f641.tar.gz
xmobar-2b13b5cf6595d81280c95eb9cf507a9817e3f641.tar.bz2
Add some optimization
Diffstat (limited to 'src')
-rw-r--r--src/Xmobar/Plugins/Monitors/Cpu.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Cpu.hs b/src/Xmobar/Plugins/Monitors/Cpu.hs
index acb3cfd..3d18da3 100644
--- a/src/Xmobar/Plugins/Monitors/Cpu.hs
+++ b/src/Xmobar/Plugins/Monitors/Cpu.hs
@@ -43,10 +43,15 @@ cpuConfig = mkMConfig
type CpuDataRef = IORef [Int]
cpuData :: IO [Int]
-cpuData = cpuParser `fmap` B.readFile "/proc/stat"
+cpuData = cpuParser <$> B.readFile "/proc/stat"
+
+readInt :: B.ByteString -> Int
+readInt bs = case B.readInt bs of
+ Nothing -> 0
+ Just (i, _) -> i
cpuParser :: B.ByteString -> [Int]
-cpuParser = map (read . B.unpack) . tail . B.words . head . B.lines
+cpuParser = map readInt . tail . B.words . head . B.lines
parseCpu :: CpuDataRef -> IO [Float]
parseCpu cref =