diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-18 15:03:55 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-18 15:54:27 +0900 |
| commit | 91692846909ed191addb7ec1c34aad11392ab88b (patch) | |
| tree | 7c477055e432fd43a98e5dddc016e07dcfc67f60 /crates/shirabe/src/command | |
| parent | 4ae58baf8618f5fe916ba2a69faaca93514134ce (diff) | |
| download | php-shirabe-91692846909ed191addb7ec1c34aad11392ab88b.tar.gz php-shirabe-91692846909ed191addb7ec1c34aad11392ab88b.tar.zst php-shirabe-91692846909ed191addb7ec1c34aad11392ab88b.zip | |
perf(regex): eliminate per-call clone overhead in preg_* dispatch
regex::Regex::clone() does not share the underlying meta engine's
search-cache pool, so every fresh clone pays a ~10us warmup cost on
its first use. Two changes together eliminate this across nearly all
preg_* call sites:
- A php_regex! macro resolves PHP-style patterns to a per-call-site
&'static regex::Regex (via regex-macro's LazyLock), applied at the
majority of call sites throughout the codebase.
- Call sites still passing dynamic pattern strings go through
PATTERN_CACHE, which now stores Arc<(Regex, bool)> and hands out
Arc::clone()s instead of cloning the Regex itself.
PregPattern::resolve() returns a ResolvedPattern enum (Arc or
'static reference) rather than an owned Regex, so neither path ever
clones the Regex proper.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command')
| -rw-r--r-- | crates/shirabe/src/command/archive_command.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/command/bump_command.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/command/config_command.rs | 58 | ||||
| -rw-r--r-- | crates/shirabe/src/command/create_project_command.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/command/diagnose_command.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/command/fund_command.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/command/global_command.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/command/init_command.rs | 20 | ||||
| -rw-r--r-- | crates/shirabe/src/command/package_discovery_trait.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/command/remove_command.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/command/repository_command.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/command/script_alias_command.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/command/show_command.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/command/update_command.rs | 9 |
14 files changed, 95 insertions, 57 deletions
diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index 2a099c89..cd2d1648 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -27,7 +27,7 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::{LogicException, get_debug_type}; +use shirabe_php_shim::{LogicException, get_debug_type, php_regex}; #[derive(Debug)] pub struct ArchiveCommand { @@ -379,7 +379,7 @@ impl ArchiveCommand { if let Some(version_str) = &version { let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::match3( - r"{@(stable|RC|beta|alpha|dev)$}i", + php_regex!(r"{@(stable|RC|beta|alpha|dev)$}i"), version_str, Some(&mut matches), ) { diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs index e6c565c1..8f27fcb8 100644 --- a/crates/shirabe/src/command/bump_command.rs +++ b/crates/shirabe/src/command/bump_command.rs @@ -19,7 +19,9 @@ use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::{PhpMixed, file_get_contents, file_put_contents, is_writable, strtolower}; +use shirabe_php_shim::{ + PhpMixed, file_get_contents, file_put_contents, is_writable, php_regex, strtolower, +}; #[derive(Debug)] pub struct BumpCommand { @@ -171,7 +173,7 @@ impl BumpCommand { let packages_filter = if !packages_filter.is_empty() { let packages_filter: Vec<String> = packages_filter .iter() - .map(|constraint| Preg::replace(r"{[:= ].+}", "", constraint)) + .map(|constraint| Preg::replace(php_regex!(r"{[:= ].+}"), "", constraint)) .collect(); let unique_lower: Vec<String> = packages_filter .iter() diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 6c2e7777..6d40c307 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -24,7 +24,7 @@ use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge, escapeshellcmd, exec, explode, file_exists, file_get_contents, implode, in_array, is_array, - is_bool, is_dir, is_numeric, is_object, is_string, json_encode, str_replace, strpos, + is_bool, is_dir, is_numeric, is_object, is_string, json_encode, php_regex, str_replace, strpos, strtolower, system, touch, var_export, }; use shirabe_semver::VersionParser; @@ -350,7 +350,7 @@ impl Command for ConfigCommand { let mut value: PhpMixed; let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - "/^repos?(?:itories)?(?:\\.(.+))?/", + php_regex!("/^repos?(?:itories)?(?:\\.(.+))?/"), &setting_key, Some(&mut matches), ) { @@ -589,7 +589,7 @@ impl Command for ConfigCommand { // handle preferred-install per-package config let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - "/^preferred-install\\.(.+)/", + php_regex!("/^preferred-install\\.(.+)/"), &setting_key, Some(&mut matches), ) { @@ -630,7 +630,7 @@ impl Command for ConfigCommand { // handle allow-plugins config setting elements true or false to add/remove let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - "{^allow-plugins\\.([a-zA-Z0-9/*-]+)}", + php_regex!("{^allow-plugins\\.([a-zA-Z0-9/*-]+)}"), &setting_key, Some(&mut matches), ) { @@ -703,7 +703,7 @@ impl Command for ConfigCommand { // handle repositories let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - "/^repos?(?:itories)?\\.(.+)/", + php_regex!("/^repos?(?:itories)?\\.(.+)/"), &setting_key, Some(&mut matches), ) { @@ -778,7 +778,11 @@ impl Command for ConfigCommand { // handle extra let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); - if Preg::is_match3("/^extra\\.(.+)/", &setting_key, Some(&mut matches)) { + if Preg::is_match3( + php_regex!("/^extra\\.(.+)/"), + &setting_key, + Some(&mut matches), + ) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -851,7 +855,11 @@ impl Command for ConfigCommand { // handle suggest let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); - if Preg::is_match3("/^suggest\\.(.+)/", &setting_key, Some(&mut matches)) { + if Preg::is_match3( + php_regex!("/^suggest\\.(.+)/"), + &setting_key, + Some(&mut matches), + ) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -889,7 +897,11 @@ impl Command for ConfigCommand { // handle platform let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); - if Preg::is_match3("/^platform\\.(.+)/", &setting_key, Some(&mut matches)) { + if Preg::is_match3( + php_regex!("/^platform\\.(.+)/"), + &setting_key, + Some(&mut matches), + ) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -1013,7 +1025,9 @@ impl Command for ConfigCommand { // handle auth let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - "/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/", + php_regex!( + "/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/" + ), &setting_key, Some(&mut matches), ) { @@ -1153,7 +1167,11 @@ impl Command for ConfigCommand { // Check if the header is in correct "Name: Value" format let mut header_parts: IndexMap<CaptureKey, String> = IndexMap::new(); - if !Preg::is_match3("/^[^:]+:\\s*.+$/", header, Some(&mut header_parts)) { + if !Preg::is_match3( + php_regex!("/^[^:]+:\\s*.+$/"), + header, + Some(&mut header_parts), + ) { return Err(RuntimeException { message: format!( "Header \"{}\" is not in \"Header-Name: Header-Value\" format", @@ -1208,7 +1226,11 @@ impl Command for ConfigCommand { // handle script let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); - if Preg::is_match3("/^scripts\\.(.+)/", &setting_key, Some(&mut matches)) { + if Preg::is_match3( + php_regex!("/^scripts\\.(.+)/"), + &setting_key, + Some(&mut matches), + ) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -1407,7 +1429,11 @@ impl ConfigCommand { || (key == "repositories" && k.is_none())) { let mut new_k = k.clone().unwrap_or_default(); - new_k.push_str(&Preg::replace("{^config\\.}", "", &format!("{}.", key))); + new_k.push_str(&Preg::replace( + php_regex!("{^config\\.}"), + "", + &format!("{}.", key), + )); k = Some(new_k); self.list_configuration( value_inner, @@ -1466,13 +1492,13 @@ impl ConfigCommand { } else { k.clone().unwrap() }; - let id = Preg::replace("{\\..*$}", "", &id_source); + let id = Preg::replace(php_regex!("{\\..*$}"), "", &id_source); let id = Preg::replace( - "{[^a-z0-9]}i", + php_regex!("{[^a-z0-9]}i"), "-", &strtolower(&shirabe_php_shim::trim(&id, Some(" \t\n\r\0\u{0B}"))), ); - let id = Preg::replace("{-+}", "-", &id); + let id = Preg::replace(php_regex!("{-+}"), "-", &id); format!("https://getcomposer.org/doc/06-config.md#{}", id) }; if is_string(&raw_val) @@ -1707,7 +1733,7 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)> ( Box::new(|val| { PhpMixed::Bool(Preg::is_match3( - "/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i", + php_regex!("/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i"), val.as_string().unwrap_or(""), None, )) diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index 4544cb63..9a2c4755 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -735,7 +735,7 @@ impl CreateProjectCommand { let ok = { let mut matched: IndexMap<CaptureKey, String> = IndexMap::new(); let ok = Preg::is_match3( - &format!( + format!( "{{^[^,\\s]*?@({})$}}i", implode( "|", diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index e457fbb2..d726efd4 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -44,8 +44,8 @@ use shirabe_php_shim::{ PHP_BINARY, PHP_EOL, PHP_VERSION, PHP_VERSION_ID, PHP_WINDOWS_VERSION_BUILD, PhpMixed, defined, disk_free_space, extension_loaded, file_exists, filter_var_boolean, function_exists, get_class_err, hash, implode, ini_get, ioncube_loader_iversion, ioncube_loader_version, - is_array, is_string, ob_get_clean, ob_start, phpinfo, rtrim, str_contains, str_replace, - str_starts_with, strpos, strstr, strtolower, trim, version_compare, + is_array, is_string, ob_get_clean, ob_start, php_regex, phpinfo, rtrim, str_contains, + str_replace, str_starts_with, strpos, strstr, strtolower, trim, version_compare, }; #[derive(Debug)] @@ -1176,7 +1176,9 @@ impl DiagnoseCommand { let mut phpinfo_match: IndexMap<CaptureKey, String> = IndexMap::new(); if phpinfo_str.is_some() && Preg::is_match3( - "{Configure Command(?: *</td><td class=\"v\">| *=> *)(.*?)(?:</td>|$)}m", + php_regex!( + "{Configure Command(?: *</td><td class=\"v\">| *=> *)(.*?)(?:</td>|$)}m" + ), phpinfo_str.as_ref().unwrap(), Some(&mut phpinfo_match), ) diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs index 65ae2c94..c40a3760 100644 --- a/crates/shirabe/src/command/fund_command.rs +++ b/crates/shirabe/src/command/fund_command.rs @@ -14,7 +14,7 @@ use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::MatchAllConstraint; @@ -60,8 +60,10 @@ impl FundCommand { .and_then(|v| v.as_string()) .unwrap_or(""); if r#type == "github" - && let Some(matches) = - Preg::is_match_with_indexed_captures(r"{^https://github.com/([^/]+)$}", &url) + && let Some(matches) = Preg::is_match_with_indexed_captures( + php_regex!(r"{^https://github.com/([^/]+)$}"), + &url, + ) && let Some(sponsor) = matches.into_iter().nth(1) { url = format!("https://github.com/sponsors/{}", sponsor); diff --git a/crates/shirabe/src/command/global_command.rs b/crates/shirabe/src/command/global_command.rs index a1f5f72e..dd1ec9c2 100644 --- a/crates/shirabe/src/command/global_command.rs +++ b/crates/shirabe/src/command/global_command.rs @@ -15,7 +15,7 @@ use shirabe_external_packages::symfony::console::input::ArrayInput; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::input::StringInput; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::{LogicException, RuntimeException, chdir}; +use shirabe_php_shim::{LogicException, RuntimeException, chdir, php_regex}; use std::path::Path; #[derive(Debug)] @@ -100,7 +100,7 @@ impl GlobalCommand { } let new_input_str = Preg::replace4( - r"{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}", + php_regex!(r"{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}"), "", &Self::input_to_string(&*input.borrow())?, 1, @@ -153,7 +153,10 @@ impl Command for GlobalCommand { input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, ) -> anyhow::Result<i64> { - let tokens = Preg::split(r"{\s+}", &Self::input_to_string(&*input.borrow())?); + let tokens = Preg::split( + php_regex!(r"{\s+}"), + &Self::input_to_string(&*input.borrow())?, + ); let mut args: Vec<String> = vec![]; for token in &tokens { if !token.is_empty() && !token.starts_with('-') { diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index f0f07a56..6b3503b0 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -28,7 +28,7 @@ use shirabe_php_shim::{ FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PHP_SERVER, PhpMixed, array_flip_strings, array_intersect_key, array_map, basename, empty, explode, file, file_exists, file_get_contents, file_put_contents, get_current_user, implode, is_dir, - is_string, preg_quote, realpath, str_replace, strpos, strtolower, trim, ucwords, + is_string, php_regex, preg_quote, realpath, str_replace, strpos, strtolower, trim, ucwords, }; use shirabe_spdx_licenses::SpdxLicenses; @@ -143,7 +143,7 @@ impl Command for InitCommand { if options.contains_key("name") && !Preg::is_match( - r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D", + php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"), options .get("name") .and_then(|v| v.as_string()) @@ -556,7 +556,7 @@ impl Command for InitCommand { } if !Preg::is_match( - r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D", + php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"), value.as_string().unwrap_or(""), ) { return Err(InvalidArgumentException { @@ -877,7 +877,7 @@ impl Command for InitCommand { value_str }; - if !Preg::is_match(r"{^[^/][A-Za-z0-9\-_/]+/$}", &value_or_default) + if !Preg::is_match(php_regex!(r"{^[^/][A-Za-z0-9\-_/]+/$}"), &value_or_default) { return Err(InvalidArgumentException { message: format!( @@ -921,7 +921,7 @@ impl InitCommand { ) -> anyhow::Result<IndexMap<String, Option<String>>> { let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#, + php_regex!(r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#), author, Some(&mut m), ) { @@ -988,7 +988,7 @@ impl InitCommand { let namespace: Vec<String> = array_map( |part: &String| { - let part = Preg::replace(r"/[^a-z0-9]/i", " ", part); + let part = Preg::replace(php_regex!(r"/[^a-z0-9]/i"), " ", part); let part = ucwords(&part); str_replace(" ", "", &part) }, @@ -1015,7 +1015,7 @@ impl InitCommand { { *self.git_config.borrow_mut() = Some(IndexMap::new()); let mut m: IndexMap<CaptureKey, Vec<String>> = IndexMap::new(); - if Preg::is_match_all3(r"{^([^=]+)=(.*)$}m", &output, Some(&mut m)) { + if Preg::is_match_all3(php_regex!(r"{^([^=]+)=(.*)$}m"), &output, Some(&mut m)) { let keys: Vec<String> = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); let values: Vec<String> = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); @@ -1174,14 +1174,14 @@ impl InitCommand { fn sanitize_package_name_component(&self, name: &str) -> String { let name = Preg::replace( - r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}", + php_regex!(r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}"), "$1$3-$2$4", name, ); let name = strtolower(&name); - let name = Preg::replace(r"{^[_.-]+|[_.-]+$|[^a-z0-9_.-]}u", "", &name); + let name = Preg::replace(php_regex!(r"{^[_.-]+|[_.-]+$|[^a-z0-9_.-]}u"), "", &name); - Preg::replace(r"{([_.-]){2,}}u", "$1", &name) + Preg::replace(php_regex!(r"{([_.-]){2,}}u"), "$1", &name) } fn get_default_package_name(&self) -> String { diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs index e5427514..f8f7cede 100644 --- a/crates/shirabe/src/command/package_discovery_trait.rs +++ b/crates/shirabe/src/command/package_discovery_trait.rs @@ -24,7 +24,7 @@ use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ Exception, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, array_keys, array_slice, asort, explode, file_get_contents, implode, in_array, is_array, is_file, - is_numeric, json_decode, levenshtein, strlen, strpos, trim, + is_numeric, json_decode, levenshtein, php_regex, strlen, strpos, trim, }; /// @internal @@ -145,7 +145,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { for mut requirement in requires_norm { if requirement.contains_key("version") && Preg::is_match( - r"{^\d+(\.\d+)?$}", + php_regex!(r"{^\d+(\.\d+)?$}"), requirement.get("version").map(|s| s.as_str()).unwrap_or(""), ) { @@ -337,7 +337,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( - r"{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}", + php_regex!(r"{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}"), &selection, Some(&mut m), ) { diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs index e7686efd..776fca79 100644 --- a/crates/shirabe/src/command/remove_command.rs +++ b/crates/shirabe/src/command/remove_command.rs @@ -396,7 +396,7 @@ impl Command for RemoveCommand { .unwrap_or_default(); let type_keys_refs: Vec<&str> = type_keys.iter().map(|s| s.as_str()).collect(); let matches_in_type = Preg::grep( - &base_package::package_name_to_regexp(package), + base_package::package_name_to_regexp(package), &type_keys_refs, ); @@ -409,7 +409,7 @@ impl Command for RemoveCommand { let alt_type_keys_refs: Vec<&str> = alt_type_keys.iter().map(|s| s.as_str()).collect(); let matches_in_alt_type = Preg::grep( - &base_package::package_name_to_regexp(package), + base_package::package_name_to_regexp(package), &alt_type_keys_refs, ); diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs index 06ecfb4f..c42b70c4 100644 --- a/crates/shirabe/src/command/repository_command.rs +++ b/crates/shirabe/src/command/repository_command.rs @@ -15,7 +15,8 @@ use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ - InvalidArgumentException, PHP_URL_HOST, PhpMixed, RuntimeException, parse_url, strtolower, + InvalidArgumentException, PHP_URL_HOST, PhpMixed, RuntimeException, parse_url, php_regex, + strtolower, }; #[derive(Debug)] @@ -287,7 +288,7 @@ impl Command for RepositoryCommand { })); } let arg1_str = arg1.as_deref().unwrap(); - let repo_config: PhpMixed = if Preg::is_match(r"{^\s*\{}", arg1_str) { + let repo_config: PhpMixed = if Preg::is_match(php_regex!(r"{^\s*\{}"), arg1_str) { JsonFile::parse_json(Some(arg1_str), None)? } else { if arg2.is_none() { diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs index 17629162..5cc4af58 100644 --- a/crates/shirabe/src/command/script_alias_command.rs +++ b/crates/shirabe/src/command/script_alias_command.rs @@ -10,7 +10,7 @@ use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::{InvalidArgumentException, LogicException, PhpMixed, is_string}; +use shirabe_php_shim::{InvalidArgumentException, LogicException, PhpMixed, is_string, php_regex}; #[derive(Debug)] pub struct ScriptAliasCommand { @@ -138,7 +138,7 @@ impl Command for ScriptAliasCommand { // TODO(phase-c): InputInterface lacks to_string; use a placeholder until it is modeled. let input_as_string = String::new(); let _ = input; - let script_alias_input = Preg::replace4(r"{^\S+ ?}", "", &input_as_string, 1); + let script_alias_input = Preg::replace4(php_regex!(r"{^\S+ ?}"), "", &input_as_string, 1); let mut flags = indexmap::IndexMap::new(); flags.insert( "script-alias-input".to_string(), diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index a63e08cf..8d1f67ff 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -41,8 +41,8 @@ use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, - array_search, date, date_format_to_strftime, extension_loaded, in_array, realpath, strtolower, - version_compare, + array_search, date, date_format_to_strftime, extension_loaded, in_array, php_regex, realpath, + strtolower, version_compare, }; use shirabe_semver::Semver; use shirabe_semver::constraint::AnyConstraint; @@ -2775,7 +2775,7 @@ impl ShowCommand { let mut groups: IndexMap<CaptureKey, String> = IndexMap::new(); if major_only && Preg::is_match3( - r"{^(?P<zero_major>(?:0\.)+)?(?P<first_meaningful>\d+)\.}", + php_regex!(r"{^(?P<zero_major>(?:0\.)+)?(?P<first_meaningful>\d+)\.}"), &package.get_version(), Some(&mut groups), ) @@ -2802,7 +2802,8 @@ impl ShowCommand { } if patch_only { - let trimmed_version = Preg::replace(r"{(\.0)+$}D", "", &package.get_version()); + let trimmed_version = + Preg::replace(php_regex!(r"{(\.0)+$}D"), "", &package.get_version()); let parts_needed = if trimmed_version.starts_with('0') { 4 } else { diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 0163f6bc..0d212350 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -31,7 +31,7 @@ use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_filter, array_intersect, - array_keys, array_merge_map, array_search_in_vec, in_array, strtolower, + array_keys, array_merge_map, array_search_in_vec, in_array, php_regex, strtolower, }; use shirabe_semver::Intervals; use shirabe_semver::constraint::MultiConstraint; @@ -184,7 +184,7 @@ impl Command for UpdateCommand { if !packages.is_empty() { let allowlist_packages_with_requirements: Vec<String> = array_filter(&packages, |pkg: &String| -> bool { - Preg::is_match(r"{\S+[ =:]\S+}", pkg) + Preg::is_match(php_regex!(r"{\S+[ =:]\S+}"), pkg) }); for (package, constraint) in self.format_requirements(allowlist_packages_with_requirements.clone())? @@ -194,7 +194,8 @@ impl Command for UpdateCommand { // replace the foo/bar:req by foo/bar in the allowlist for package in &allowlist_packages_with_requirements { - let package_name = Preg::replace(r"{^([^ =:]+)[ =:].*$}", "$1", package); + let package_name = + Preg::replace(php_regex!(r"{^([^ =:]+)[ =:].*$}"), "$1", package); if let Some(idx) = array_search_in_vec(package, &packages) { packages[idx] = package_name; } @@ -266,7 +267,7 @@ impl Command for UpdateCommand { continue; } let matches = Preg::is_match_with_indexed_captures( - r"{^(\d+\.\d+\.\d+)}", + php_regex!(r"{^(\d+\.\d+\.\d+)}"), &package.get_version(), ); let Some(matches) = matches else { |
