feat: lazy regex

This commit is contained in:
2025-05-05 14:12:32 +08:00
parent 6f7ef266a6
commit f16740b837
2 changed files with 4 additions and 3 deletions

View File

@@ -1,5 +1,3 @@
use std::fmt::{Debug, Formatter, Result};
use ecow::EcoString;
use crate::ty::internal::Const;

View File

@@ -1,6 +1,8 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::ops::Deref;
use std::sync::LazyLock;
use derive_more::Constructor;
use ecow::EcoString;
use regex::Regex;
@@ -39,9 +41,10 @@ impl Display for Symbol {
}
}
static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"^[a-zA-Z\_][a-zA-Z0-9\_\'\-]*$"#).unwrap());
impl Symbol {
fn normal(&self) -> bool {
!Regex::new(r#"^[a-zA-Z\_][a-zA-Z0-9\_\'\-]*$"#).unwrap().is_match(self)
!REGEX.is_match(self)
}
}