diff --git a/src/lib.rs b/src/lib.rs index e24d7073f..d0f3e36e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -493,6 +493,15 @@ mod test { } } + // Ensure that the global CPU name is always empty. + #[test] + fn check_global_cpu_name() { + let mut s = System::new(); + assert_eq!(s.global_cpu_info().name(), ""); + s.refresh_cpu_all(); + assert_eq!(s.global_cpu_info().name(), ""); + } + // In case `Process::updated` is misused, `System::refresh_processes` might remove them // so this test ensures that it doesn't happen. #[test] diff --git a/src/unix/apple/cpu.rs b/src/unix/apple/cpu.rs index 11ff26ca8..624ad8bd9 100644 --- a/src/unix/apple/cpu.rs +++ b/src/unix/apple/cpu.rs @@ -22,7 +22,7 @@ impl CpusWrapper { Self { global_cpu: Cpu { inner: CpuInner::new( - "0".to_owned(), + String::new(), Arc::new(CpuData::new(std::ptr::null_mut(), 0)), 0, String::new(), diff --git a/src/unix/linux/cpu.rs b/src/unix/linux/cpu.rs index af6210abe..cb611ca41 100644 --- a/src/unix/linux/cpu.rs +++ b/src/unix/linux/cpu.rs @@ -102,13 +102,7 @@ impl CpusWrapper { if &line[..4] != b"cpu " { return; } - let mut parts = line.split(|x| *x == b' ').filter(|s| !s.is_empty()); - if first { - to_str!(parts.next().unwrap_or(&[])) - .clone_into(&mut self.global_cpu.inner.name); - } else { - parts.next(); - } + let mut parts = line.split(|x| *x == b' ').filter(|s| !s.is_empty()).skip(1); self.global_cpu.inner.set( parts.next().map(to_u64).unwrap_or(0), parts.next().map(to_u64).unwrap_or(0), diff --git a/src/windows/cpu.rs b/src/windows/cpu.rs index ff5979cbe..a05544e09 100644 --- a/src/windows/cpu.rs +++ b/src/windows/cpu.rs @@ -256,7 +256,7 @@ impl CpusWrapper { Self { global: Cpu { inner: CpuInner::new_with_values( - "Total CPU".to_owned(), + String::new(), String::new(), String::new(), 0,