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/downloader/svn_downloader.rs | |
| 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/downloader/svn_downloader.rs')
| -rw-r--r-- | crates/shirabe/src/downloader/svn_downloader.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index cd48daeb..b2dd7f58 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -16,7 +16,7 @@ use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; -use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, version_compare}; +use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, php_regex, version_compare}; #[derive(Debug)] pub struct SvnDownloader { @@ -278,7 +278,7 @@ impl VcsDownloader for SvnDownloader { } let changes_str = changes.unwrap(); - let changes: Vec<String> = Preg::split(r"{\s*\r?\n\s*}", &changes_str) + let changes: Vec<String> = Preg::split(php_regex!(r"{\s*\r?\n\s*}"), &changes_str) .into_iter() .map(|elem| format!(" {}", elem)) .collect(); @@ -364,8 +364,8 @@ impl VcsDownloader for SvnDownloader { to_reference: &str, path: &str, ) -> anyhow::Result<String> { - if Preg::is_match(r"{@(\d+)$}", from_reference) - && Preg::is_match(r"{@(\d+)$}", to_reference) + if Preg::is_match(php_regex!(r"{@(\d+)$}"), from_reference) + && Preg::is_match(php_regex!(r"{@(\d+)$}"), to_reference) { // retrieve the svn base url from the checkout folder let command = vec![ @@ -411,8 +411,8 @@ impl VcsDownloader for SvnDownloader { }; // strip paths from references and only keep the actual revision - let from_revision = Preg::replace(r"{.*@(\d+)$}", "$1", from_reference); - let to_revision = Preg::replace(r"{.*@(\d+)$}", "$1", to_reference); + let from_revision = Preg::replace(php_regex!(r"{.*@(\d+)$}"), "$1", from_reference); + let to_revision = Preg::replace(php_regex!(r"{.*@(\d+)$}"), "$1", to_reference); let command = vec![ "svn".to_string(), @@ -469,7 +469,7 @@ impl ChangeReportInterface for SvnDownloader { Some(path), ); - Ok(if Preg::is_match("{^ *[^X ] +}m", &output) { + Ok(if Preg::is_match(php_regex!("{^ *[^X ] +}m"), &output) { Some(output) } else { None |
