diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | fed0a6e7ac361af9b963c1f62411b1a85478230c (patch) | |
| tree | 5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe-symfony-finder/src | |
| parent | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff) | |
| download | php-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-symfony-finder/src')
| -rw-r--r-- | crates/shirabe-symfony-finder/src/finder.rs | 14 |
1 files changed, 8 insertions, 6 deletions
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 [("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")] { |
