From 70e463708b461efd61a611061cfee0539d28645a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 06:36:42 +0900 Subject: 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) --- crates/shirabe/src/package/locker.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'crates/shirabe/src/package/locker.rs') diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index 10350d78..a4d28861 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -29,7 +29,7 @@ use shirabe_external_packages::seld::json_lint::ParsingException; use shirabe_php_shim::{ DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys, array_map, array_merge, file_get_contents, filemtime, function_exists, hash, in_array_loose, - in_array_strict, is_int, ksort, php_regex, realpath, strcmp, strtolower, touch2, trim, usort, + is_int, ksort, php_regex, realpath, strcmp, strtolower, touch2, trim, usort, }; /// Reads/writes project lockfile (composer.lock). @@ -476,18 +476,12 @@ impl Locker { let aliases: Vec> = array_map( |alias: &IndexMap| { let mut alias = alias.clone(); - let version = alias - .get("version") - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(); - if in_array_strict( - version, - &[ - PhpMixed::String("dev-master".to_string()), - PhpMixed::String("dev-trunk".to_string()), - PhpMixed::String("dev-default".to_string()), - ], + if matches!( + alias + .get("version") + .and_then(|v| v.as_string()) + .unwrap_or(""), + "dev-master" | "dev-trunk" | "dev-default" ) { alias.insert( "version".to_string(), -- cgit v1.3.1