From 6c2fc6652fc14bc3a678d7ad39ab4b9762d6127c Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 16 May 2025 03:46:54 +0300 Subject: [PATCH] monitor: optimize path search for CPU frequency directory --- src/monitor.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/monitor.rs b/src/monitor.rs index 0b3f7fb..80605ff 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -399,11 +399,13 @@ pub fn get_cpu_global_info(cpu_cores: &[CpuCoreInfo]) -> CpuGlobalInfo { eprintln!("Warning: {e}"); 0 }); - let path = (0..core_count) - .map(|i| PathBuf::from(format!("/sys/devices/system/cpu/cpu{i}/cpufreq/"))) - .find(|path| path.exists()); - if let Some(test_path_buf) = path { - cpufreq_base_path_buf = test_path_buf; + + for i in 0..core_count { + let test_path = PathBuf::from(format!("/sys/devices/system/cpu/cpu{i}/cpufreq/")); + if test_path.exists() { + cpufreq_base_path_buf = test_path; + break; // Exit the loop as soon as we find a valid path + } } }