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-semver/src/version_parser.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'crates/shirabe-semver/src/version_parser.rs') diff --git a/crates/shirabe-semver/src/version_parser.rs b/crates/shirabe-semver/src/version_parser.rs index 79c368bb..8d86de2e 100644 --- a/crates/shirabe-semver/src/version_parser.rs +++ b/crates/shirabe-semver/src/version_parser.rs @@ -4,7 +4,9 @@ use crate::constraint::AnyConstraint; use crate::constraint::MatchAllConstraint; use crate::constraint::MultiConstraint; use crate::constraint::SimpleConstraint; -use shirabe_php_shim::{php_regex, preg_match, preg_quote, preg_replace, preg_split}; +use shirabe_php_shim::{ + php_regex, preg_is_match, preg_match, preg_quote, preg_replace, preg_split, +}; // Regex to match pre-release data (sort of). // @@ -194,30 +196,26 @@ impl VersionParser { } } - let extra_message = if preg_match( + let extra_message = if preg_is_match( format!( "{{ +as +{}(?:@(?:{}))?$}}", preg_quote(&version, None), STABILITIES_REGEX ), &full_version, - ) - .is_some() - { + ) { format!( " in \"{}\", the alias must be an exact version", full_version ) - } else if preg_match( + } else if preg_is_match( format!( "{{^{}(?:@(?:{}))? +as +}}", preg_quote(&version, None), STABILITIES_REGEX ), &full_version, - ) - .is_some() - { + ) { format!( " in \"{}\", the alias source must be an exact version, if it is a branch name \ you should prefix it with dev-", @@ -615,7 +613,7 @@ impl VersionParser { // dev-foobar except if the constraint uses a known operator, in which // case it must be a parse error if version_str.ends_with("-dev") - && preg_match(php_regex!("{^[0-9a-zA-Z-./]+$}"), &version_str).is_some() + && preg_is_match(php_regex!("{^[0-9a-zA-Z-./]+$}"), &version_str) { self.normalize( &format!("dev-{}", &version_str[..version_str.len() - 4]), @@ -640,12 +638,10 @@ impl VersionParser { } if op == "<" || op == ">=" { let modifier_pattern = format!("{{-{}$}}", MODIFIER_REGEX); - if preg_match( + if !preg_is_match( &modifier_pattern, &shirabe_php_shim::strtolower(&version_str), - ) - .is_none() - && !version_str.starts_with("dev-") + ) && !version_str.starts_with("dev-") { version = format!("{}-dev", version); } -- cgit v1.3.1-4-g156e