Skip to content

Commit

Permalink
Merge pull request #194 from keisku/use-lazylock
Browse files Browse the repository at this point in the history
Remove `once_cell` dependency
  • Loading branch information
cgwalters authored Aug 22, 2024
2 parents de8fd72 + 7112644 commit f8d6425
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ getset = "0.1.1"
strum = "0.26.2"
strum_macros = "0.26.2"
regex = "~1.10.5"
once_cell = "~1.19.0"

[dev-dependencies]
tempfile = "3.2.0"
Expand Down
14 changes: 9 additions & 5 deletions src/runtime/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
};
use derive_builder::Builder;
use getset::{CopyGetters, Getters, MutGetters, Setters};
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{de, Deserialize, Deserializer, Serialize};
use std::path::PathBuf;
use std::sync::OnceLock;
use strum_macros::{Display as StrumDisplay, EnumString};

#[derive(
Expand Down Expand Up @@ -623,12 +623,16 @@ where
Ok(value)
}

static EXEC_CPU_AFFINITY_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^(\d+(-\d+)?)(,\d+(-\d+)?)*$").expect("Failed to create regex for execCPUAffinity")
});
fn exec_cpu_affinity_regex() -> &'static Regex {
static EXEC_CPU_AFFINITY_REGEX: OnceLock<Regex> = OnceLock::new();
EXEC_CPU_AFFINITY_REGEX.get_or_init(|| {
Regex::new(r"^(\d+(-\d+)?)(,\d+(-\d+)?)*$")
.expect("Failed to create regex for execCPUAffinity")
})
}

fn validate_cpu_affinity(s: &str) -> Result<(), String> {
if !EXEC_CPU_AFFINITY_REGEX.is_match(s) {
if !exec_cpu_affinity_regex().is_match(s) {
return Err(format!("Invalid execCPUAffinity format: {}", s));
}

Expand Down

0 comments on commit f8d6425

Please sign in to comment.