From cc93bacb7260d3164d9411baad84953e74bb9db9 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Fri, 12 Apr 2019 11:52:42 +0200 Subject: [PATCH] src/tools/procfs.rs: simplify read_cpuinfo() Signed-off-by: Christian Ebner --- src/tools/procfs.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/tools/procfs.rs b/src/tools/procfs.rs index e9778db0..1cb27172 100644 --- a/src/tools/procfs.rs +++ b/src/tools/procfs.rs @@ -189,17 +189,12 @@ pub fn read_cpuinfo() -> Result { let mut content_iter = content.split(":"); match (content_iter.next(), content_iter.next()) { (Some(key), Some(value)) => { - let mut key_iter = key.split_whitespace(); - match (key_iter.next(), key_iter.next()) { - (Some("processor"), None) => - cpuinfo.cpus += 1, - (Some("model"), Some("name")) => - cpuinfo.model = value.trim().to_string(), - (Some("cpu"), Some("MHz")) => - cpuinfo.mhz = value.trim().parse::()?, - (Some("flags"), None) => - cpuinfo.hvm = value.contains(" vmx ") || value.contains(" svm "), - (Some("physical"), Some("id")) => { + match key.trim_end() { + "processor" => cpuinfo.cpus += 1, + "model name" => cpuinfo.model = value.trim().to_string(), + "cpu MHz" => cpuinfo.mhz = value.trim().parse::()?, + "flags" => cpuinfo.hvm = value.contains(" vmx ") || value.contains(" svm "), + "physical id" => { let id = value.trim().parse::()?; socket_ids.insert(id); },