diff --git a/src/numa.rs b/src/numa.rs index 00c0f5d64..9f890a4bd 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 {