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-class-map-generator | |
| 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-class-map-generator')
| -rw-r--r-- | crates/shirabe-class-map-generator/src/class_map.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe-class-map-generator/src/class_map_generator.rs | 13 |
2 files changed, 8 insertions, 9 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map.rs b/crates/shirabe-class-map-generator/src/class_map.rs index 1d980129..4870d481 100644 --- a/crates/shirabe-class-map-generator/src/class_map.rs +++ b/crates/shirabe-class-map-generator/src/class_map.rs @@ -1,7 +1,7 @@ //! ref: composer/vendor/composer/class-map-generator/src/ClassMap.php use indexmap::IndexMap; -use shirabe_php_shim::{OutOfBoundsException, preg_match, rtrim, strpos, strtr}; +use shirabe_php_shim::{OutOfBoundsException, preg_is_match, rtrim, strpos, strtr}; #[derive(Debug, Clone)] pub struct PsrViolationEntry { @@ -66,7 +66,7 @@ impl ClassMap { for (class, paths) in &self.ambiguous_classes { let paths: Vec<String> = paths .iter() - .filter(|path| preg_match(duplicates_filter, &strtr(path, "\\", "/")).is_none()) + .filter(|path| !preg_is_match(duplicates_filter, &strtr(path, "\\", "/"))) .cloned() .collect(); if !paths.is_empty() { diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs index da2f62c5..254e3a3f 100644 --- a/crates/shirabe-class-map-generator/src/class_map_generator.rs +++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs @@ -5,9 +5,9 @@ use crate::file_list::FileList; use crate::php_file_parser::PhpFileParser; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PATHINFO_EXTENSION, RuntimeException, explode, - getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_match, preg_quote, preg_replace, - preg_replace_callback, realpath, str_replace, stream_get_wrappers, strlen, strpos, strrpos, - strtr, substr, + getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_is_match, preg_match, preg_quote, + preg_replace, preg_replace_callback, realpath, str_replace, stream_get_wrappers, strlen, + strpos, strrpos, strtr, substr, }; use shirabe_symfony_finder::Finder; use std::path::PathBuf; @@ -134,8 +134,7 @@ impl ClassMapGenerator { continue; } - let is_stream_wrapper_path = - preg_match(&self.stream_wrappers_regex, &file_path).is_some(); + let is_stream_wrapper_path = preg_is_match(&self.stream_wrappers_regex, &file_path); if !Self::is_absolute_path(&file_path) && !is_stream_wrapper_path { file_path = format!("{}/{}", cwd, file_path); file_path = Self::normalize_path(&file_path); @@ -183,11 +182,11 @@ impl ClassMapGenerator { // check the realpath of the file against the excluded paths as the path might be a symlink and the excluded path is realpath'd so symlink are resolved if let Some(ref excluded) = excluded { - if preg_match(excluded, &strtr(&real_path, "\\", "/")).is_some() { + if preg_is_match(excluded, &strtr(&real_path, "\\", "/")) { continue; } // check non-realpath of file for directories symlink in project dir - if preg_match(excluded, &strtr(&file_path, "\\", "/")).is_some() { + if preg_is_match(excluded, &strtr(&file_path, "\\", "/")) { continue; } } |
