From 5cf08670dff591cb6d1df28dab4eefea936f2bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Mon, 30 Oct 2023 19:22:38 -0300 Subject: [PATCH] Speed up procfs scanning --- src/kill.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/kill.rs b/src/kill.rs index 7d028de..c57b33a 100644 --- a/src/kill.rs +++ b/src/kill.rs @@ -23,17 +23,7 @@ pub fn choose_victim( let mut processes = fs::read_dir("/proc/")? .filter_map(|e| e.ok()) - .filter_map(|entry| { - entry - .path() - .file_name() - .unwrap_or_else(|| OsStr::new("0")) - .to_str() - .unwrap_or("0") - .trim() - .parse::() - .ok() - }) + .filter_map(|entry| entry.file_name().to_str()?.trim().parse::().ok()) .filter(|pid| *pid > 1) .filter_map(|pid| Process::from_pid(pid, proc_buf).ok());