From 36dee7bace5b9e00359e66dcd24de58e2f498a30 Mon Sep 17 00:00:00 2001 From: Aethdv Date: Wed, 22 Jul 2026 11:31:46 +0200 Subject: [PATCH 1/2] Make `parse_cpu_indices` more elegant Replaced the messy manual loops with a clean iterator chain that skips parsing errors instead of crashing. Bench: 2669518 --- src/numa.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/numa.rs b/src/numa.rs index 00c0f5d64..ada6cf3e1 100644 --- a/src/numa.rs +++ b/src/numa.rs @@ -256,26 +256,18 @@ impl NumaConfig { } fn parse_cpu_indices(cpu_ids: &str) -> Vec { - if cpu_ids.is_empty() { - return Vec::new(); - } - - let mut indices = Vec::new(); - for segment in cpu_ids.split(',').filter(|s| !s.is_empty()) { - let parts: Vec<_> = segment.split('-').collect(); - match parts.len() { - 1 => indices.push(parts[0].parse::().unwrap()), - 2 => { - let first = parts[0].parse::().unwrap(); - let last = parts[1].parse::().unwrap(); - for cpu in first..=last { - indices.push(cpu); - } - } - _ => {} - } - } - indices + cpu_ids + .split(',') + .filter(|s| !s.is_empty()) + .filter_map(|s| { + let (a, b) = s.split_once('-').unwrap_or((s, s)); + let start = a.parse::().ok()?; + let end = b.parse::().ok()?; + + Some(start..=end) + }) + .flatten() + .collect() } fn remove_whitespace(s: String) -> String { From a32193fb4128a2a91dd9a624ebad241c5d117044 Mon Sep 17 00:00:00 2001 From: Aethdv Date: Wed, 22 Jul 2026 11:35:38 +0200 Subject: [PATCH 2/2] Formatting Perfect Bench: 2669518 --- src/numa.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/numa.rs b/src/numa.rs index ada6cf3e1..9f890a4bd 100644 --- a/src/numa.rs +++ b/src/numa.rs @@ -263,7 +263,7 @@ fn parse_cpu_indices(cpu_ids: &str) -> Vec { let (a, b) = s.split_once('-').unwrap_or((s, s)); let start = a.parse::().ok()?; let end = b.parse::().ok()?; - + Some(start..=end) }) .flatten()