mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-06 18:13:45 +08:00
perf: simplify code logic and improve efficiency
This commit is contained in:
parent
bc39d56b0f
commit
9b04721b3d
@ -795,21 +795,24 @@ impl CoreManager {
|
|||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut pids = Vec::new();
|
|
||||||
|
|
||||||
for line in output.lines() {
|
let pids: Vec<u32> = output
|
||||||
if line.contains(process_name) {
|
.lines()
|
||||||
|
.filter(|line| line.contains(process_name))
|
||||||
|
.filter_map(|line| {
|
||||||
println!("[进程检查] 发现匹配行: {}", line);
|
println!("[进程检查] 发现匹配行: {}", line);
|
||||||
let parts: Vec<&str> = line.split(',').collect();
|
let parts: Vec<&str> = line.split(',').collect();
|
||||||
if parts.len() >= 2 {
|
if parts.len() >= 2 {
|
||||||
let pid_str = parts[1].trim_matches('"');
|
let pid_str = parts[1].trim_matches('"');
|
||||||
if let Ok(pid) = pid_str.parse::<u32>() {
|
pid_str.parse::<u32>().ok().map(|pid| {
|
||||||
println!("[进程检查] 发现进程 PID: {}", pid);
|
println!("[进程检查] 发现进程 PID: {}", pid);
|
||||||
pids.push(pid);
|
pid
|
||||||
}
|
})
|
||||||
}
|
} else {
|
||||||
}
|
None
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
println!("[进程检查] 共发现 {} 个相关进程", pids.len());
|
println!("[进程检查] 共发现 {} 个相关进程", pids.len());
|
||||||
Ok(pids)
|
Ok(pids)
|
||||||
@ -820,17 +823,22 @@ impl CoreManager {
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
println!("[进程检查] Linux系统,使用pgrep命令");
|
println!("[进程检查] Linux系统,使用pgrep命令");
|
||||||
let output = Command::new("pgrep").arg("-f").arg(process_name).output()?;
|
let output = Command::new("pgrep")
|
||||||
|
.arg("-f")
|
||||||
|
.arg(process_name)
|
||||||
|
.output()?;
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut pids = Vec::new();
|
|
||||||
|
|
||||||
for line in output.lines() {
|
let pids: Vec<u32> = output
|
||||||
if let Ok(pid) = line.trim().parse::<u32>() {
|
.lines()
|
||||||
|
.filter_map(|line| {
|
||||||
|
line.trim().parse::<u32>().ok().map(|pid| {
|
||||||
println!("[进程检查] 发现进程 PID: {}", pid);
|
println!("[进程检查] 发现进程 PID: {}", pid);
|
||||||
pids.push(pid);
|
pid
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
println!("[进程检查] 共发现 {} 个相关进程", pids.len());
|
println!("[进程检查] 共发现 {} 个相关进程", pids.len());
|
||||||
Ok(pids)
|
Ok(pids)
|
||||||
@ -846,20 +854,23 @@ impl CoreManager {
|
|||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut pids = Vec::new();
|
|
||||||
|
|
||||||
for line in output.lines() {
|
let pids: Vec<u32> = output
|
||||||
if line.contains(process_name) {
|
.lines()
|
||||||
|
.filter(|line| line.contains(process_name))
|
||||||
|
.filter_map(|line| {
|
||||||
println!("[进程检查] 发现匹配行: {}", line);
|
println!("[进程检查] 发现匹配行: {}", line);
|
||||||
let parts: Vec<&str> = line.split_whitespace().collect();
|
let parts: Vec<&str> = line.split_whitespace().collect();
|
||||||
if !parts.is_empty() {
|
if !parts.is_empty() {
|
||||||
if let Ok(pid) = parts[0].parse::<u32>() {
|
parts[0].parse::<u32>().ok().map(|pid| {
|
||||||
println!("[进程检查] 发现进程 PID: {}", pid);
|
println!("[进程检查] 发现进程 PID: {}", pid);
|
||||||
pids.push(pid);
|
pid
|
||||||
}
|
})
|
||||||
}
|
} else {
|
||||||
}
|
None
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
println!("[进程检查] 共发现 {} 个相关进程", pids.len());
|
println!("[进程检查] 共发现 {} 个相关进程", pids.len());
|
||||||
Ok(pids)
|
Ok(pids)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user