aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/vcs/hg_driver.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-18 15:03:55 +0900
committernsfisis <nsfisis@gmail.com>2026-07-18 15:54:27 +0900
commit91692846909ed191addb7ec1c34aad11392ab88b (patch)
tree7c477055e432fd43a98e5dddc016e07dcfc67f60 /crates/shirabe/src/repository/vcs/hg_driver.rs
parent4ae58baf8618f5fe916ba2a69faaca93514134ce (diff)
downloadphp-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/repository/vcs/hg_driver.rs')
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index f987eb4b..a346094c 100644
--- a/crates/shirabe/src/repository/vcs/hg_driver.rs
+++ b/crates/shirabe/src/repository/vcs/hg_driver.rs
@@ -12,7 +12,7 @@ use crate::util::Url;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable};
+use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex};
#[derive(Debug)]
pub struct HgDriver {
@@ -59,8 +59,11 @@ impl HgDriver {
}.into());
}
- let sanitized =
- Preg::replace(r"{[^a-z0-9]}i", "-", &Url::sanitize(self.inner.url.clone()));
+ let sanitized = Preg::replace(
+ php_regex!(r"{[^a-z0-9]}i"),
+ "-",
+ &Url::sanitize(self.inner.url.clone()),
+ );
self.repo_dir = format!("{}/{}/", cache_vcs_dir, sanitized);
let mut fs = Filesystem::new(None);
@@ -242,7 +245,7 @@ impl HgDriver {
for tag in self.inner.process.borrow().split_lines(&output) {
if !tag.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"(^([^\s]+)\s+\d+:(.*)$)", &tag, Some(&mut m)) {
+ if Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag, Some(&mut m)) {
tags.insert(
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(),
@@ -272,7 +275,11 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"(^([^\s]+)\s+\d+:([a-f0-9]+))", &branch, Some(&mut m)) {
+ if Preg::match3(
+ php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"),
+ &branch,
+ Some(&mut m),
+ ) {
let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if !name.starts_with('-') {
branches.insert(
@@ -293,7 +300,11 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)", &branch, Some(&mut m)) {
+ if Preg::match3(
+ php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"),
+ &branch,
+ Some(&mut m),
+ ) {
let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if !name.starts_with('-') {
bookmarks.insert(
@@ -320,7 +331,9 @@ impl HgDriver {
deep: bool,
) -> anyhow::Result<bool> {
if Preg::is_match(
- r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i",
+ php_regex!(
+ r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i"
+ ),
url,
) {
return Ok(true);