Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace lazy_static with std::sync::LazyLock #198

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion brush-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fancy-regex = "0.13.0"
futures = "0.3.31"
indexmap = "2.6.0"
itertools = "0.13.0"
lazy_static = "1.5.0"
rand = "0.8.5"
thiserror = "1.0.64"
tracing = "0.1.40"
Expand Down
10 changes: 5 additions & 5 deletions brush-core/src/builtins/declare.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use itertools::Itertools;
use std::io::Write;
use std::{io::Write, sync::LazyLock};

use crate::{
builtins, commands,
Expand Down Expand Up @@ -322,10 +322,10 @@ impl DeclareCommand {
// We need to handle the case of someone invoking `declare array[index]`.
// In such case, we ignore the index and treat it as a declaration of
// the array.
lazy_static::lazy_static! {
static ref ARRAY_AND_INDEX_RE: fancy_regex::Regex =
fancy_regex::Regex::new(r"^(.*?)\[(.*?)\]$").unwrap();
}
static ARRAY_AND_INDEX_RE: LazyLock<fancy_regex::Regex> =
LazyLock::new(|| {
fancy_regex::Regex::new(r"^(.*?)\[(.*?)\]$").unwrap()
});
if let Some(captures) = ARRAY_AND_INDEX_RE.captures(s)? {
name = captures.get(1).unwrap().as_str().to_owned();
assigned_index = Some(captures.get(2).unwrap().as_str().to_owned());
Expand Down
9 changes: 5 additions & 4 deletions brush-core/src/keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashSet;
use std::sync::LazyLock;

use crate::Shell;

Expand Down Expand Up @@ -31,10 +32,10 @@ fn get_keywords(sh_mode_only: bool) -> HashSet<String> {
keywords
}

lazy_static::lazy_static! {
pub(crate) static ref SH_MODE_KEYWORDS: HashSet<String> = get_keywords(true);
pub(crate) static ref KEYWORDS: HashSet<String> = get_keywords(false);
}
pub(crate) static SH_MODE_KEYWORDS: LazyLock<HashSet<String>> =
LazyLock::new(|| get_keywords(true));
pub(crate) static KEYWORDS: LazyLock<HashSet<String>> =
LazyLock::new(|| get_keywords(false));

pub fn is_keyword(shell: &Shell, name: &str) -> bool {
if shell.options.sh_mode {
Expand Down
Loading
Loading