diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-06 06:36:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-06 06:36:42 +0900 |
| commit | 70e463708b461efd61a611061cfee0539d28645a (patch) | |
| tree | 267066f1a6ac872d256de99a4ffafb1adf31f311 /crates/shirabe/src/dependency_resolver/problem.rs | |
| parent | 791ef1cd465597ff43dab4216c4b00e9e4160da8 (diff) | |
| download | php-shirabe-70e463708b461efd61a611061cfee0539d28645a.tar.gz php-shirabe-70e463708b461efd61a611061cfee0539d28645a.tar.zst php-shirabe-70e463708b461efd61a611061cfee0539d28645a.zip | |
refactor: replace literal-list in_array_strict with matches!
Call sites whose haystack was an inline array of literals (or a local
built solely to feed one) had to wrap both sides in PhpMixed just to
compare, allocating a String per element on every call. matches! does
the same test against the underlying &str/i64/Option directly, so the
PhpMixed round trip and its .to_string()/.clone()/.iter().map()
conversions are gone.
Sites whose haystack is a runtime value or a named constant array are
left on in_array_strict: inlining a named constant would duplicate its
contents at the call site.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/dependency_resolver/problem.rs')
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/problem.rs | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs index b3da1e09..09adafea 100644 --- a/crates/shirabe/src/dependency_resolver/problem.rs +++ b/crates/shirabe/src/dependency_resolver/problem.rs @@ -13,8 +13,8 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; use shirabe_php_shim::{ - LogicException, PhpMixed, defined, extension_loaded, implode, in_array_strict, loosely_compare, - php_regex, phpversion, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos, + LogicException, PhpMixed, defined, extension_loaded, implode, loosely_compare, php_regex, + phpversion, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos, strtolower, substr, substr_count, version_compare, }; use shirabe_semver::constraint::AnyConstraint; @@ -211,7 +211,6 @@ impl Problem { let mut templates: IndexMap<String, IndexMap<String, IndexMap<String, String>>> = IndexMap::new(); let parser = VersionParser::new(); - let deduplicatable_rule_types = [rule::RULE_PACKAGE_REQUIRES, rule::RULE_PACKAGE_CONFLICT]; for rule in rules { let rule_ref = rule.borrow(); let mut message = rule_ref.get_pretty_string( @@ -223,12 +222,9 @@ impl Problem { learned_pool, )?; let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); - let matched = if in_array_strict( + let matched = if matches!( rule_ref.get_reason(), - &deduplicatable_rule_types - .iter() - .map(|t| PhpMixed::Int(*t)) - .collect::<Vec<_>>(), + rule::RULE_PACKAGE_REQUIRES | rule::RULE_PACKAGE_CONFLICT ) { Preg::is_match3( php_regex!( @@ -964,13 +960,7 @@ impl Problem { && c.get_version() == "dev-master" { for candidate in &packages { - if in_array_strict( - candidate.get_version().to_string(), - &[ - PhpMixed::String("dev-default".to_string()), - PhpMixed::String("dev-main".to_string()), - ], - ) { + if matches!(candidate.get_version().as_str(), "dev-default" | "dev-main") { suffix = format!( " Perhaps dev-master was renamed to {}?", candidate.get_pretty_version() |
