From fed0a6e7ac361af9b963c1f62411b1a85478230c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: 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) --- crates/shirabe/src/downloader/git_downloader.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'crates/shirabe/src/downloader/git_downloader.rs') 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 = 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)); } -- cgit v1.3.1-4-g156e