diff options
author | Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> | 2024-08-12 16:30:35 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-12 07:30:35 +0000 |
commit | a797969efed10c46c7cf93e5eb7a03b52d6ca7bc (patch) | |
tree | 4321d4d361794c6f7f98e5bb0a0386da35b93b85 /components/script/dom/bindings | |
parent | f38d1574bcb27449b8878192ac0ea3ba2ce824e7 (diff) | |
download | servo-a797969efed10c46c7cf93e5eb7a03b52d6ca7bc.tar.gz servo-a797969efed10c46c7cf93e5eb7a03b52d6ca7bc.zip |
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>
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/str.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 7ec868698c8..3489a2da617 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -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) } |