diff options
author | Yiyu Lin <linyiyu1992@gmail.com> | 2023-04-13 09:08:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 03:08:01 +0200 |
commit | d790ea7d533c3c48b09a2f16f3fef549aa96be78 (patch) | |
tree | b31fc35baf1f634054f52e94626f0399d187b99b /ops | |
parent | 19c3e4f6dc31fd78e2793d0596d6a9cc3a30580a (diff) |
refactor(cli,ext,ops): cleanup `regex` with `lazy-regex` (#17296)
- bump deps: the newest `lazy-regex` need newer `oncecell` and
`regex`
- reduce `unwrap`
- remove dep `lazy_static`
- make more regex cached
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ops')
-rw-r--r-- | ops/Cargo.toml | 1 | ||||
-rw-r--r-- | ops/lib.rs | 28 |
2 files changed, 12 insertions, 17 deletions
diff --git a/ops/Cargo.toml b/ops/Cargo.toml index 55754108a..b8bbfd07d 100644 --- a/ops/Cargo.toml +++ b/ops/Cargo.toml @@ -15,6 +15,7 @@ path = "./lib.rs" proc-macro = true [dependencies] +lazy-regex.workspace = true once_cell.workspace = true pmutil = "0.5.3" proc-macro-crate = "1.1.3" diff --git a/ops/lib.rs b/ops/lib.rs index aee6c8c03..41f69d9fc 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -1,7 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use attrs::Attributes; -use once_cell::sync::Lazy; use optimizer::BailoutReason; use optimizer::Optimizer; use proc_macro::TokenStream; @@ -9,7 +8,6 @@ use proc_macro2::Span; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use quote::ToTokens; -use regex::Regex; use syn::parse; use syn::parse_macro_input; use syn::punctuated::Punctuated; @@ -859,30 +857,26 @@ fn is_unit_result(ty: impl ToTokens) -> bool { } fn is_resource_id(arg: impl ToTokens) -> bool { - static RE: Lazy<Regex> = - Lazy::new(|| Regex::new(r#": (?:deno_core :: )?ResourceId$"#).unwrap()); - RE.is_match(&tokens(arg)) + let re = lazy_regex::regex!(r#": (?:deno_core :: )?ResourceId$"#); + re.is_match(&tokens(arg)) } fn is_mut_ref_opstate(arg: impl ToTokens) -> bool { - static RE: Lazy<Regex> = - Lazy::new(|| Regex::new(r#": & mut (?:deno_core :: )?OpState$"#).unwrap()); - RE.is_match(&tokens(arg)) + let re = lazy_regex::regex!(r#": & mut (?:deno_core :: )?OpState$"#); + re.is_match(&tokens(arg)) } fn is_rc_refcell_opstate(arg: &syn::FnArg) -> bool { - static RE: Lazy<Regex> = Lazy::new(|| { - Regex::new(r#": Rc < RefCell < (?:deno_core :: )?OpState > >$"#).unwrap() - }); - RE.is_match(&tokens(arg)) + let re = + lazy_regex::regex!(r#": Rc < RefCell < (?:deno_core :: )?OpState > >$"#); + re.is_match(&tokens(arg)) } fn is_handle_scope(arg: &syn::FnArg) -> bool { - static RE: Lazy<Regex> = Lazy::new(|| { - Regex::new(r#": & mut (?:deno_core :: )?v8 :: HandleScope(?: < '\w+ >)?$"#) - .unwrap() - }); - RE.is_match(&tokens(arg)) + let re = lazy_regex::regex!( + r#": & mut (?:deno_core :: )?v8 :: HandleScope(?: < '\w+ >)?$"# + ); + re.is_match(&tokens(arg)) } fn is_future(ty: impl ToTokens) -> bool { |