Replace the lazy_static crate whth std::sync::LazyLock in components/script (#33004)

* replace in str.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace navigator.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace htmlmetaelement.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace document.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace cssstyledeclaration.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace script_runtime.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace window_named_properties.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* reduce dependency lazy_static

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* reduce lazy in script_runtime.rs

 `Mutex::new()`  is const contexts. I think that `JS_ENGINE` is need not lazy initialize.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

---------

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
This commit is contained in:
Hayashi Mikihiro 2024-08-12 16:30:35 +09:00 committed by GitHub
parent f38d1574bc
commit a797969efe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 98 additions and 104 deletions

View file

@ -9,13 +9,13 @@ use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use std::sync::LazyLock;
use std::{fmt, ops, str};
use chrono::prelude::{Utc, Weekday};
use chrono::{Datelike, TimeZone};
use cssparser::CowRcStr;
use html5ever::{LocalName, Namespace};
use lazy_static::lazy_static;
use num_traits::Zero;
use regex::Regex;
use servo_atoms::Atom;
@ -430,10 +430,10 @@ impl DOMString {
/// <https://html.spec.whatwg.org/multipage/#valid-floating-point-number>
pub fn is_valid_floating_point_number_string(&self) -> bool {
lazy_static! {
static ref RE: Regex =
Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap();
}
static RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap()
});
RE.is_match(&self.0) && self.parse_floating_point_number().is_some()
}
@ -537,13 +537,14 @@ impl DOMString {
/// <https://html.spec.whatwg.org/multipage/#valid-e-mail-address>
pub fn is_valid_email_address_string(&self) -> bool {
lazy_static! {
static ref RE: Regex = Regex::new(concat!(
static RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(concat!(
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?",
r"(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
))
.unwrap();
}
.unwrap()
});
RE.is_match(&self.0)
}