aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2011-03-17 04:26:20 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2011-03-17 04:26:20 +0100
commit6522f580110e25c5f030c65f830fda430ccc0f47 (patch)
treeb64fcd1555e120b11813fd237faed69346eec743
parent753ce61de08350579e2b8016c69b1b058d676fc8 (diff)
downloadvicious-legacy-6522f580110e25c5f030c65f830fda430ccc0f47.tar.xz
cpu: another 10 percent optimization from Joerg
-rw-r--r--widgets/cpu.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/widgets/cpu.lua b/widgets/cpu.lua
index 319da3e..978b5f4 100644
--- a/widgets/cpu.lua
+++ b/widgets/cpu.lua
@@ -1,7 +1,8 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
--- * (c) 2010, Adrian C. <anrxc@sysphere.org>
+-- * (c) 2011, Adrian C. <anrxc@sysphere.org>
-- * (c) 2009, Lucas de Vries <lucas@glacicle.com>
+-- * (c) 2011, Jörg Thalheim <jthalheim@gmail.com>
---------------------------------------------------
-- {{{ Grab environment
@@ -11,7 +12,7 @@ local setmetatable = setmetatable
local math = { floor = math.floor }
local table = { insert = table.insert }
local string = {
- find = string.find,
+ sub = string.sub,
gmatch = string.gmatch
}
-- }}}
@@ -32,12 +33,12 @@ local function worker(format)
-- Get CPU stats
for line in io.lines("/proc/stat") do
- if string.find(line, "^cpu") then
- cpu_lines[#cpu_lines+1] = {}
+ if string.sub(line, 1, 3) ~= "cpu" then break end
- for i in string.gmatch(line, "[%s]+([%d]+)") do
- table.insert(cpu_lines[#cpu_lines], i)
- end
+ cpu_lines[#cpu_lines+1] = {}
+
+ for i in string.gmatch(line, "[%s]+([^%s]+)") do
+ table.insert(cpu_lines[#cpu_lines], i)
end
end