aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commitfed0a6e7ac361af9b963c1f62411b1a85478230c (patch)
tree5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/downloader
parente093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff)
downloadphp-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites, which only tested the Option. They now call preg_is_match, which lets the regex engine skip capture tracking. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/downloader')
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs6
-rw-r--r--crates/shirabe/src/downloader/fossil_downloader.rs4
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs21
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs20
4 files changed, 23 insertions, 28 deletions
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 85e05bea..d7c6eec1 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -11,8 +11,8 @@ use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_keys,
- array_reverse, array_shift, dirname, implode, in_array_strict, preg_match, preg_quote, rtrim,
- str_replace, strtolower, usort,
+ array_reverse, array_shift, dirname, implode, in_array_strict, preg_is_match, preg_quote,
+ rtrim, str_replace, strtolower, usort,
};
/// Downloaders manager.
@@ -430,7 +430,7 @@ impl DownloadManager {
"{{^{}$}}i",
str_replace("\\*", ".*", &preg_quote(pattern, None)),
);
- if preg_match(&pattern_regex, &package.get_name()).is_some() {
+ if preg_is_match(&pattern_regex, &package.get_name()) {
if "dist" == preference || (!package.is_dev() && "auto" == preference) {
return "dist".to_string();
}
diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs
index 40d5153f..96886ca0 100644
--- a/crates/shirabe/src/downloader/fossil_downloader.rs
+++ b/crates/shirabe/src/downloader/fossil_downloader.rs
@@ -13,7 +13,7 @@ use crate::util::Filesystem;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, impl_php_class, php_regex, preg_match, preg_split,
+ PhpMixed, RuntimeException, impl_php_class, php_regex, preg_is_match, preg_split,
};
#[derive(Debug)]
@@ -228,7 +228,7 @@ impl VcsDownloader for FossilDownloader {
};
for line in lines {
- if preg_match(&match_pattern, &line).is_some() {
+ if preg_is_match(&match_pattern, &line) {
break;
}
log.push_str(&line);
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index be3205b5..a8a4344d 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -19,8 +19,9 @@ use crate::util::Url;
use indexmap::IndexMap;
use shirabe_php_shim::{
CaptureKey, CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class,
- implode, in_array_strict, is_dir, php_regex, preg_match, preg_match_all, preg_quote,
- preg_replace, preg_split, realpath, rtrim, strlen, strpos, substr, trim, version_compare,
+ implode, in_array_strict, is_dir, php_regex, preg_is_match, preg_match, preg_match_all,
+ preg_quote, preg_replace, preg_split, realpath, rtrim, strlen, strpos, substr, trim,
+ version_compare,
};
#[derive(Debug)]
@@ -298,13 +299,12 @@ impl GitDownloader {
// check whether non-commitish are branches or tags, and fetch branches with the remote name
let git_ref = reference.to_string();
- if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference).is_none()
+ if !preg_is_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference)
&& branches.is_some()
- && preg_match(
+ && preg_is_match(
format!("{{^\\s+composer/{}$}}m", preg_quote(reference, None)),
branches.as_deref().unwrap_or(""),
)
- .is_some()
{
let mut command1: Vec<String> = vec!["git".to_string(), "checkout".to_string()];
command1.extend(force.clone());
@@ -345,19 +345,17 @@ impl GitDownloader {
}
// try to checkout branch by name and then reset it so it's on the proper branch name
- if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference).is_some() {
+ if preg_is_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference) {
// add 'v' in front of the branch if it was stripped when generating the pretty name
if branches.is_some()
- && preg_match(
+ && !preg_is_match(
format!("{{^\\s+composer/{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .is_none()
- && preg_match(
+ && preg_is_match(
format!("{{^\\s+composer/v{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .is_some()
{
branch = format!("v{}", branch);
}
@@ -642,8 +640,7 @@ impl GitDownloader {
}
fn get_short_hash(&self, reference: &str) -> String {
- if !self.inner.io.is_verbose()
- && preg_match(php_regex!(r"{^[0-9a-f]{40}$}"), reference).is_some()
+ if !self.inner.io.is_verbose() && preg_is_match(php_regex!(r"{^[0-9a-f]{40}$}"), reference)
{
return substr(reference, 0, Some(10));
}
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index 42152eb3..93b860f0 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -16,8 +16,8 @@ use crate::util::ProcessExecutor;
use crate::util::Svn as SvnUtil;
use indexmap::IndexMap;
use shirabe_php_shim::{
- CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_match, preg_replace,
- preg_split, version_compare,
+ CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_is_match,
+ preg_match, preg_replace, preg_split, version_compare,
};
#[derive(Debug)]
@@ -353,8 +353,8 @@ impl VcsDownloader for SvnDownloader {
to_reference: &str,
path: &str,
) -> anyhow::Result<String> {
- if preg_match(php_regex!(r"{@(\d+)$}"), from_reference).is_some()
- && preg_match(php_regex!(r"{@(\d+)$}"), to_reference).is_some()
+ 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![
@@ -452,13 +452,11 @@ impl ChangeReportInterface for SvnDownloader {
Some(path),
);
- Ok(
- if preg_match(php_regex!("{^ *[^X ] +}m"), &output).is_some() {
- Some(output)
- } else {
- None
- },
- )
+ Ok(if preg_is_match(php_regex!("{^ *[^X ] +}m"), &output) {
+ Some(output)
+ } else {
+ None
+ })
}
}