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-symfony-finder/src/finder.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/shirabe-symfony-finder/src') diff --git a/crates/shirabe-symfony-finder/src/finder.rs b/crates/shirabe-symfony-finder/src/finder.rs index b32418db..fa29a3a7 100644 --- a/crates/shirabe-symfony-finder/src/finder.rs +++ b/crates/shirabe-symfony-finder/src/finder.rs @@ -9,7 +9,9 @@ use crate::glob::Glob; use chrono::{NaiveDate, NaiveDateTime}; use indexmap::IndexSet; -use shirabe_php_shim::{file_exists, glob, is_dir, php_regex, preg_match, preg_quote, rtrim}; +use shirabe_php_shim::{ + file_exists, glob, is_dir, php_regex, preg_is_match, preg_match, preg_quote, rtrim, +}; use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; @@ -310,7 +312,7 @@ impl Finder { let dir = rtrim(dir, Some("/")); - if preg_match(php_regex!("#^(ssh2\\.)?s?ftp://#"), &dir).is_some() { + if preg_is_match(php_regex!("#^(ssh2\\.)?s?ftp://#"), &dir) { format!("{dir}/") } else { dir @@ -591,7 +593,7 @@ fn exclude_accept( }; let path = path.replace('\\', "/"); - return preg_match(pattern, &path).is_none(); + return !preg_is_match(pattern, &path); } true @@ -618,14 +620,14 @@ fn to_regex_path(pattern: &str) -> String { /// `MultiplePcreFilterIterator::isAccepted`. fn is_accepted(string: &str, match_regexps: &[String], nomatch_regexps: &[String]) -> bool { for regex in nomatch_regexps { - if preg_match(regex, string).is_some() { + if preg_is_match(regex, string) { return false; } } if !match_regexps.is_empty() { for regex in match_regexps { - if preg_match(regex, string).is_some() { + if preg_is_match(regex, string) { return true; } } @@ -655,7 +657,7 @@ fn is_regex(str: &str) -> bool { .unwrap_or_default(); if start == end { - return preg_match(php_regex!("/[*?[:alnum:] \\\\]/"), &start).is_none(); + return !preg_is_match(php_regex!("/[*?[:alnum:] \\\\]/"), &start); } for (open, close) in [("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")] { -- cgit v1.3.1-4-g156e