aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/installer_test.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/tests/installer_test.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/tests/installer_test.rs')
-rw-r--r--crates/shirabe/tests/installer_test.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/crates/shirabe/tests/installer_test.rs b/crates/shirabe/tests/installer_test.rs
index e5006b86..ba3c0e86 100644
--- a/crates/shirabe/tests/installer_test.rs
+++ b/crates/shirabe/tests/installer_test.rs
@@ -50,7 +50,7 @@ use shirabe_external_packages::symfony::console::output::output_interface::{
OutputInterface, VERBOSITY_NORMAL,
};
use shirabe_external_packages::symfony::console::output::stream_output::StreamOutput;
-use shirabe_php_shim::{PREG_SPLIT_DELIM_CAPTURE, PhpMixed};
+use shirabe_php_shim::{PREG_SPLIT_DELIM_CAPTURE, PhpMixed, php_regex};
use shirabe_semver::VersionParser;
use shirabe_semver::constraint::AnyConstraint;
@@ -550,7 +550,7 @@ fn read_test_file(
) -> IndexMap<String, String> {
let contents = std::fs::read_to_string(file).unwrap();
let tokens = Preg::split4(
- r"#(?:^|\n*)--([A-Z-]+)--\n#",
+ php_regex!(r"#(?:^|\n*)--([A-Z-]+)--\n#"),
&contents,
-1,
PREG_SPLIT_DELIM_CAPTURE,
@@ -654,7 +654,7 @@ fn load_integration_tests(path: &str) -> Vec<IntegrationCase> {
return;
}
if let Some(url) = repo.get("url").and_then(|u| u.as_str())
- && Preg::is_match(r"{^file://[^/]}", url)
+ && Preg::is_match(php_regex!(r"{^file://[^/]}"), url)
{
let new_url = format!("file://{}/{}", fixtures_str, &url[7..]);
repo["url"] = serde_json::Value::String(new_url);
@@ -1204,8 +1204,16 @@ fn do_test_integration(case: &IntegrationCase, expect_output: Option<&str>) {
if let Some(expect_output) = expect_output
&& !expect_output.is_empty()
{
- let output = Preg::replace(r"{^ - .*?\.ini$}m", "__inilist__", &output_string);
- let output = Preg::replace(r"{(__inilist__\r?\n)+}", "__inilist__\n", &output);
+ let output = Preg::replace(
+ php_regex!(r"{^ - .*?\.ini$}m"),
+ "__inilist__",
+ &output_string,
+ );
+ let output = Preg::replace(
+ php_regex!(r"{(__inilist__\r?\n)+}"),
+ "__inilist__\n",
+ &output,
+ );
assert_string_matches_format(expect_output.trim_end(), output.trim_end(), &output_string);
}
}