From 7f4c9c6779062f53240113b153204dd6ac9179e2 Mon Sep 17 00:00:00 2001 From: keisku Date: Tue, 30 Jul 2024 03:15:32 +0000 Subject: [PATCH 1/2] use LazyLock, std library, to remove once_cell, 3rd party library Signed-off-by: keisku --- Cargo.toml | 1 - src/runtime/process.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c17ae8232c..c2aa8dee9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/runtime/process.rs b/src/runtime/process.rs index 20d197a1c1..8ef97229b7 100644 --- a/src/runtime/process.rs +++ b/src/runtime/process.rs @@ -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::LazyLock; use strum_macros::{Display as StrumDisplay, EnumString}; #[derive( @@ -623,7 +623,7 @@ where Ok(value) } -static EXEC_CPU_AFFINITY_REGEX: Lazy = Lazy::new(|| { +static EXEC_CPU_AFFINITY_REGEX: LazyLock = LazyLock::new(|| { Regex::new(r"^(\d+(-\d+)?)(,\d+(-\d+)?)*$").expect("Failed to create regex for execCPUAffinity") }); From 7112644980050e66dba2c3587cabd47514fd9164 Mon Sep 17 00:00:00 2001 From: keisku Date: Thu, 22 Aug 2024 05:36:24 +0000 Subject: [PATCH 2/2] use OnceLock instead Signed-off-by: keisku --- src/runtime/process.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/runtime/process.rs b/src/runtime/process.rs index 8ef97229b7..79ef8544fc 100644 --- a/src/runtime/process.rs +++ b/src/runtime/process.rs @@ -7,7 +7,7 @@ use getset::{CopyGetters, Getters, MutGetters, Setters}; use regex::Regex; use serde::{de, Deserialize, Deserializer, Serialize}; use std::path::PathBuf; -use std::sync::LazyLock; +use std::sync::OnceLock; use strum_macros::{Display as StrumDisplay, EnumString}; #[derive( @@ -623,12 +623,16 @@ where Ok(value) } -static EXEC_CPU_AFFINITY_REGEX: LazyLock = LazyLock::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 = 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)); }