From 91692846909ed191addb7ec1c34aad11392ab88b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Jul 2026 15:03:55 +0900 Subject: 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 --- .../src/symfony/console/command/command.rs | 5 +++-- .../symfony/console/completion/completion_input.rs | 4 ++-- .../symfony/console/descriptor/json_descriptor.rs | 6 +++--- .../symfony/console/formatter/output_formatter.rs | 15 +++++++++------ .../src/symfony/console/helper/helper.rs | 14 +++++++++----- .../src/symfony/console/helper/table.rs | 4 ++-- .../src/symfony/console/input/argv_input.rs | 5 +++-- .../src/symfony/console/input/input.rs | 4 ++-- .../src/symfony/console/input/input_option.rs | 4 ++-- .../src/symfony/console/input/string_input.rs | 16 +++++++++++----- .../src/symfony/console/output/stream_output.rs | 5 ++++- .../symfony/console/question/choice_question.rs | 4 ++-- .../src/symfony/console/terminal.rs | 10 +++++----- .../src/symfony/finder/finder.rs | 6 +++--- .../src/symfony/process/process.rs | 22 ++++++++++++++-------- 15 files changed, 74 insertions(+), 50 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony') diff --git a/crates/shirabe-external-packages/src/symfony/console/command/command.rs b/crates/shirabe-external-packages/src/symfony/console/command/command.rs index 81eb3c08..ef4a471a 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command/command.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command/command.rs @@ -11,7 +11,7 @@ use crate::symfony::console::input::input_interface::InputInterface; use crate::symfony::console::input::input_option::InputOption; use crate::symfony::console::output::output_interface::{self, OutputInterface}; use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; use std::cell::{Cell, Ref}; /// The base-class state of the PHP `Command` class. @@ -136,7 +136,8 @@ impl CommandData { /// Throws InvalidArgumentException when the name is invalid. fn validate_name(&self, name: &str) -> anyhow::Result> { let mut matches: Vec> = Vec::new(); - if !shirabe_php_shim::preg_match(r"/^[^\:]++(\:[^\:]++)*$/", name, &mut matches) { + if !shirabe_php_shim::preg_match(php_regex!(r"/^[^\:]++(\:[^\:]++)*$/"), name, &mut matches) + { return Ok(Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { message: format!("Command name \"{}\" is invalid.", name), diff --git a/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs b/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs index e0b8e09d..d076f8a3 100644 --- a/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs @@ -3,7 +3,7 @@ use crate::symfony::console::input::argv_input::ArgvInput; use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_option::InputOption; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; /// An input specialized for shell completion. /// @@ -30,7 +30,7 @@ impl CompletionInput { /// This is required for shell completions without COMP_WORDS support. pub fn from_string(input_str: &str, current_index: i64) -> anyhow::Result { let tokens = shirabe_php_shim::preg_match_all( - "/(?<=^|\\s)(['\"]?)(.+?)(?" special chars in given text. pub fn escape(text: &str) -> anyhow::Result { - let text = shirabe_php_shim::preg_replace("/([^\\\\]|^)([<>])/", "$1\\\\$2", text); + let text = + shirabe_php_shim::preg_replace(php_regex!("/([^\\\\]|^)([<>])/"), "$1\\\\$2", text); Ok(Self::escape_trailing_backslash(&text)) } @@ -102,7 +104,7 @@ impl OutputFormatter { let mut matches: Vec> = vec![]; if shirabe_php_shim::preg_match_all_set_order( - "/([^=]+)=([^;]+)(;|$)/", + php_regex!("/([^=]+)=([^;]+)(;|$)/"), string, &mut matches, ) == 0 @@ -121,11 +123,12 @@ impl OutputFormatter { } else if r#match[0] == "bg" { style.set_background(Some(&shirabe_php_shim::strtolower(&r#match[1]))); } else if r#match[0] == "href" { - let url = shirabe_php_shim::preg_replace("{\\\\([<>])}", "$1", &r#match[1]); + let url = + shirabe_php_shim::preg_replace(php_regex!("{\\\\([<>])}"), "$1", &r#match[1]); style.set_href(&url); } else if r#match[0] == "options" { let mut options = shirabe_php_shim::preg_match_all( - "([^,;]+)", + php_regex!("([^,;]+)"), &shirabe_php_shim::strtolower(&r#match[1]), ); let options = shirabe_php_shim::array_shift(&mut options).unwrap_or_default(); @@ -176,7 +179,7 @@ impl OutputFormatter { } let mut matches: Vec> = vec![]; - shirabe_php_shim::preg_match("~(\\n)$~", &text, &mut matches); + shirabe_php_shim::preg_match(php_regex!("~(\\n)$~"), &text, &mut matches); text = format!("{}{}", prefix, self.add_line_breaks(&text, width)); let trailing = matches.get(1).and_then(|m| m.clone()).unwrap_or_default(); text = format!("{}{}", shirabe_php_shim::rtrim(&text, Some("\n")), trailing); @@ -287,7 +290,7 @@ impl WrappableOutputFormatterInterface for OutputFormatter { let mut current_line_length: i64 = 0; let mut matches: shirabe_php_shim::PregOffsetCaptureMatches = Default::default(); shirabe_php_shim::preg_match_all_offset_capture( - &format!("#<(({open_tag_regex}) | /({close_tag_regex})?)>#ix"), + format!("#<(({open_tag_regex}) | /({close_tag_regex})?)>#ix"), message, &mut matches, ); diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs index be5eb050..20103df8 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs @@ -3,6 +3,7 @@ use crate::symfony::console::formatter::output_formatter_interface::OutputFormatterInterface; use crate::symfony::console::helper::helper_set::HelperSet; use crate::symfony::string::unicode_string::UnicodeString; +use shirabe_php_shim::php_regex; /// Helper is the base class for all helper classes. #[derive(Debug, Default)] @@ -39,7 +40,7 @@ impl Helper { /// Returns the width of a string, using mb_strwidth if it is available. /// The width is how many characters positions the string will use. pub fn width(string: &str) -> i64 { - if shirabe_php_shim::preg_match("//u", string, &mut Vec::new()) { + if shirabe_php_shim::preg_match(php_regex!("//u"), string, &mut Vec::new()) { return UnicodeString::new(string).width(false); } @@ -55,7 +56,7 @@ impl Helper { /// Returns the length of a string, using mb_strlen if it is available. /// The length is related to how many bytes the string will use. pub fn length(string: &str) -> i64 { - if shirabe_php_shim::preg_match("//u", string, &mut Vec::new()) { + if shirabe_php_shim::preg_match(php_regex!("//u"), string, &mut Vec::new()) { return UnicodeString::new(string).length(); } @@ -147,10 +148,13 @@ impl Helper { // remove <...> formatting let string = formatter.format(Some(string)).unwrap().unwrap_or_default(); // remove already formatted characters - let string = shirabe_php_shim::preg_replace("/\u{1b}\\[[^m]*m/", "", &string); + let string = shirabe_php_shim::preg_replace(php_regex!("/\u{1b}\\[[^m]*m/"), "", &string); // remove terminal hyperlinks - let string = - shirabe_php_shim::preg_replace("/\u{1b}]8;[^;]*;[^\u{1b}]*\u{1b}\\\\/", "", &string); + let string = shirabe_php_shim::preg_replace( + php_regex!("/\u{1b}]8;[^;]*;[^\u{1b}]*\u{1b}\\\\/"), + "", + &string, + ); formatter.set_decorated(is_decorated); string diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs index cae3f896..c5d7e346 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs @@ -14,7 +14,7 @@ use crate::symfony::console::helper::table_style::TableStyle; use crate::symfony::console::output::console_section_output::ConsoleSectionOutput; use crate::symfony::console::output::output_interface::OutputInterface; use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; /// A single cell within a table row. /// @@ -847,7 +847,7 @@ impl Table { let mut pad_type = style.get_pad_type(); if cell.is_table_cell() && cell.style().is_some() { let is_not_styled_by_tag = !Preg::is_match( - "/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/", + php_regex!("/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/"), &cell_str, ); if is_not_styled_by_tag { diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs index ad06da72..7c24da60 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs @@ -6,7 +6,7 @@ use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_interface::InputInterface; use crate::symfony::console::input::streamable_input_interface::StreamableInputInterface; use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; /// ArgvInput represents an input coming from the CLI arguments. /// @@ -512,7 +512,8 @@ impl std::fmt::Display for ArgvInput { .iter() .map(|token| { let mut r#match: Vec> = Vec::new(); - if shirabe_php_shim::preg_match("{^(-[^=]+=)(.+)}", token, &mut r#match) { + if shirabe_php_shim::preg_match(php_regex!("{^(-[^=]+=)(.+)}"), token, &mut r#match) + { return format!( "{}{}", r#match[1].as_deref().unwrap_or(""), diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input.rs b/crates/shirabe-external-packages/src/symfony/console/input/input.rs index 70b61851..e14ed354 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input.rs @@ -4,7 +4,7 @@ use crate::symfony::console::exception::invalid_argument_exception::InvalidArgum use crate::symfony::console::exception::runtime_exception::RuntimeException; use crate::symfony::console::input::input_definition::InputDefinition; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, PhpResource}; +use shirabe_php_shim::{PhpMixed, PhpResource, php_regex}; /// Input is the base class for all concrete Input classes. /// @@ -219,7 +219,7 @@ impl Input { /// Escapes a token through escapeshellarg if it contains unsafe chars. pub fn escape_token(&self, token: &str) -> String { let mut matches: Vec> = vec![]; - if shirabe_php_shim::preg_match("{^[\\w-]+$}", token, &mut matches) { + if shirabe_php_shim::preg_match(php_regex!("{^[\\w-]+$}"), token, &mut matches) { token.to_string() } else { shirabe_php_shim::escapeshellarg(token) diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs index bd93f490..3f8fdeaf 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs @@ -2,7 +2,7 @@ use crate::symfony::console::exception::invalid_argument_exception::InvalidArgumentException; use crate::symfony::console::exception::logic_exception::LogicException; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; #[derive(Debug, Clone)] pub struct InputOption { @@ -110,7 +110,7 @@ impl InputOption { fn normalize_shortcut(s: String) -> anyhow::Result> { let stripped = shirabe_php_shim::ltrim(&s, Some("-")); - let parts = shirabe_php_shim::preg_split(r"{(\|)-?}", &stripped); + let parts = shirabe_php_shim::preg_split(php_regex!(r"{(\|)-?}"), &stripped); let filtered: Vec = shirabe_php_shim::array_filter(&parts, |s: &String| !s.is_empty()); let result = shirabe_php_shim::implode("|", &filtered); diff --git a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs index 122e588e..c9871c34 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs @@ -6,7 +6,7 @@ use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_interface::InputInterface; use crate::symfony::console::input::streamable_input_interface::StreamableInputInterface; use indexmap::IndexMap; -use shirabe_php_shim::{CaptureKey, PhpMixed}; +use shirabe_php_shim::{CaptureKey, PhpMixed, php_regex}; /// StringInput represents an input provided as a string. /// @@ -58,14 +58,20 @@ impl StringInput { } let mut m: IndexMap> = IndexMap::new(); - if shirabe_php_shim::preg_match2(r"/\s+/A", input, &mut m, 0, cursor as usize) { + if shirabe_php_shim::preg_match2( + php_regex!(r"/\s+/A"), + input, + &mut m, + 0, + cursor as usize, + ) { if token.is_some() { tokens.push(token.take().unwrap()); } cursor += shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or("")); } else if shirabe_php_shim::preg_match2( - &format!(r#"/([^="'\s]+?)(=?)({}+)/A"#, Self::REGEX_QUOTED_STRING), + format!(r#"/([^="'\s]+?)(=?)({}+)/A"#, Self::REGEX_QUOTED_STRING), input, &mut m, 0, @@ -88,7 +94,7 @@ impl StringInput { cursor += shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or("")); } else if shirabe_php_shim::preg_match2( - &format!(r"/{}/A", Self::REGEX_QUOTED_STRING), + format!(r"/{}/A", Self::REGEX_QUOTED_STRING), input, &mut m, 0, @@ -106,7 +112,7 @@ impl StringInput { cursor += shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or("")); } else if shirabe_php_shim::preg_match2( - &format!(r"/{}/A", Self::REGEX_UNQUOTED_STRING), + format!(r"/{}/A", Self::REGEX_UNQUOTED_STRING), input, &mut m, 0, diff --git a/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs index ac85f3a4..4d8eb921 100644 --- a/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs +++ b/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs @@ -5,6 +5,7 @@ use crate::symfony::console::formatter::OutputFormatterInterface; use crate::symfony::console::output::OutputInterface; use crate::symfony::console::output::output::{DoWrite, Output}; use crate::symfony::console::output::output_interface::VERBOSITY_NORMAL; +use shirabe_php_shim::php_regex; /// StreamOutput writes the output to a given stream. /// @@ -127,7 +128,9 @@ impl StreamOutput { // See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157 let mut matches: Vec> = Vec::new(); shirabe_php_shim::preg_match( - "/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/", + php_regex!( + "/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/" + ), &term, &mut matches, ) diff --git a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs index a8cde916..848888a6 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs @@ -5,7 +5,7 @@ use crate::symfony::console::exception::logic_exception::LogicException; use crate::symfony::console::question::Question; use crate::symfony::console::question::QuestionInterface; use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; /// Represents a choice question. #[derive(Debug)] @@ -125,7 +125,7 @@ impl ChoiceQuestion { // Check for a separated comma values let mut matches: Vec> = Vec::new(); if !shirabe_php_shim::preg_match( - "/^[^,]+(?:,[^,]+)*$/", + php_regex!("/^[^,]+(?:,[^,]+)*$/"), &shirabe_php_shim::strval(&selected), &mut matches, ) { diff --git a/crates/shirabe-external-packages/src/symfony/console/terminal.rs b/crates/shirabe-external-packages/src/symfony/console/terminal.rs index cc8f8128..7fca27e8 100644 --- a/crates/shirabe-external-packages/src/symfony/console/terminal.rs +++ b/crates/shirabe-external-packages/src/symfony/console/terminal.rs @@ -1,6 +1,6 @@ //! ref: composer/vendor/symfony/console/Terminal.php -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, php_regex}; use std::cell::Cell; thread_local! { @@ -86,7 +86,7 @@ impl Terminal { let mut matches: Vec> = Vec::new(); if let Some(ansicon) = &ansicon && shirabe_php_shim::preg_match( - "/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/", + php_regex!("/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/"), &shirabe_php_shim::trim(&ansicon.to_string_lossy(), None), &mut matches, ) @@ -143,7 +143,7 @@ impl Terminal { } let mut matches: Vec> = Vec::new(); if shirabe_php_shim::preg_match( - "/rows.(\\d+);.columns.(\\d+);/i", + php_regex!("/rows.(\\d+);.columns.(\\d+);/i"), &stty_string, &mut matches, ) { @@ -159,7 +159,7 @@ impl Terminal { )))) }); } else if shirabe_php_shim::preg_match( - "/;.(\\d+).rows;.(\\d+).columns/i", + php_regex!("/;.(\\d+).rows;.(\\d+).columns/i"), &stty_string, &mut matches, ) { @@ -187,7 +187,7 @@ impl Terminal { let info = info?; let mut matches: Vec> = Vec::new(); if !shirabe_php_shim::preg_match( - "/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/", + php_regex!("/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/"), &info, &mut matches, ) { diff --git a/crates/shirabe-external-packages/src/symfony/finder/finder.rs b/crates/shirabe-external-packages/src/symfony/finder/finder.rs index 7d3bdc10..c2b6c4cd 100644 --- a/crates/shirabe-external-packages/src/symfony/finder/finder.rs +++ b/crates/shirabe-external-packages/src/symfony/finder/finder.rs @@ -10,7 +10,7 @@ use crate::composer::pcre::{CaptureKey, Preg}; use crate::symfony::finder::glob::Glob; use chrono::{NaiveDate, NaiveDateTime}; use indexmap::{IndexMap, IndexSet}; -use shirabe_php_shim::{file_exists, glob, is_dir, preg_quote, rtrim}; +use shirabe_php_shim::{file_exists, glob, is_dir, php_regex, preg_quote, rtrim}; use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; @@ -311,7 +311,7 @@ impl Finder { let dir = rtrim(dir, Some("/")); - if Preg::is_match("#^(ssh2\\.)?s?ftp://#", &dir) { + if Preg::is_match(php_regex!("#^(ssh2\\.)?s?ftp://#"), &dir) { format!("{dir}/") } else { dir @@ -660,7 +660,7 @@ fn is_regex(str: &str) -> bool { .unwrap_or_default(); if start == end { - return !Preg::is_match("/[*?[:alnum:] \\\\]/", &start); + return !Preg::is_match(php_regex!("/[*?[:alnum:] \\\\]/"), &start); } for (open, close) in [("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")] { diff --git a/crates/shirabe-external-packages/src/symfony/process/process.rs b/crates/shirabe-external-packages/src/symfony/process/process.rs index 84bed629..ecd40e7a 100644 --- a/crates/shirabe-external-packages/src/symfony/process/process.rs +++ b/crates/shirabe-external-packages/src/symfony/process/process.rs @@ -12,7 +12,7 @@ use crate::symfony::process::pipes::unix_pipes::UnixPipes; use crate::symfony::process::pipes::windows_pipes::WindowsPipes; use crate::symfony::process::process_utils::ProcessUtils; use indexmap::IndexMap; -use shirabe_php_shim::{Descriptor, PhpMixed, PhpResource}; +use shirabe_php_shim::{Descriptor, PhpMixed, PhpResource, php_regex}; use std::sync::OnceLock; /// A user-supplied callback invoked with the output type ("out"/"err") and a chunk of output. @@ -1542,13 +1542,15 @@ impl Process { let mut var_count = 0; let mut var_cache: IndexMap = IndexMap::new(); let cmd = shirabe_php_shim::preg_replace_callback( - r#"/"(?:( + php_regex!( + r#"/"(?:( [^"%!^]*+ (?: (?: !LF! | "(?:\^[%!^])?+" ) [^"%!^]*+ )++ - ) | [^"]*+ )"/x"#, + ) | [^"]*+ )"/x"# + ), |m: &[Option]| -> anyhow::Result { let m0 = m.first().cloned().flatten().unwrap_or_default(); let m1 = m.get(1).cloned().flatten(); @@ -1577,7 +1579,7 @@ impl Process { } value = format!( "\"{}\"", - shirabe_php_shim::preg_replace(r#"/(\\*)"/"#, "$1$1\\\"", &value) + shirabe_php_shim::preg_replace(php_regex!(r#"/(\\*)"/"#), "$1$1\\\"", &value) ); var_count += 1; let var = format!("{}{}", uid, var_count); @@ -1599,7 +1601,11 @@ impl Process { .map(|spec| { format!( "\"{}\"", - shirabe_php_shim::preg_replace(r#"{(\\*+)"}"#, "$1$1\\\"", &spec) + shirabe_php_shim::preg_replace( + php_regex!(r#"{(\\*+)"}"#), + "$1$1\\\"", + &spec, + ) ) }) }) @@ -1655,13 +1661,13 @@ impl Process { argument = argument.replace('\0', "?"); } if !shirabe_php_shim::preg_match( - r#"/[()%!^"<>&|\s\[\]=;*?'$]/"#, + php_regex!(r#"/[()%!^"<>&|\s\[\]=;*?'$]/"#), &argument, &mut Vec::new(), ) { return argument; } - argument = shirabe_php_shim::preg_replace(r"/(\\+)$/", "$1$1", &argument); + argument = shirabe_php_shim::preg_replace(php_regex!(r"/(\\+)$/"), "$1$1", &argument); let mut result = argument; for (from, to) in [ @@ -1682,7 +1688,7 @@ impl Process { env: &IndexMap, ) -> anyhow::Result { shirabe_php_shim::preg_replace_callback( - r#"/"\$\{:([_a-zA-Z]+[_a-zA-Z0-9]*)\}"/"#, + php_regex!(r#"/"\$\{:([_a-zA-Z]+[_a-zA-Z0-9]*)\}"/"#), |matches: &[Option]| -> anyhow::Result { let key = matches.get(1).cloned().flatten().unwrap_or_default(); match env.get(&key) { -- cgit v1.3.1