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/console/application.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/console/application.rs')
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 5dff0e61..d6a287c2 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -97,10 +97,10 @@ use shirabe_php_shim::{ LogicException as ShimLogicException, PHP_VERSION, PHP_VERSION_ID, PhpMixed, RuntimeException, bin2hex, chdir, date_default_timezone_get, date_default_timezone_set, defined, dirname, disk_free_space, extension_loaded, file_exists, file_get_contents, file_put_contents, - function_exists, getcwd, getmypid, glob, in_array_strict, ini_set, is_array, is_dir, is_file, - is_string, is_subclass_of, json_decode, memory_get_peak_usage, memory_get_usage, microtime, - php_regex, php_uname, posix_getuid, random_bytes, realpath, restore_error_handler, round, - str_contains, str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink, + function_exists, getcwd, getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, + is_subclass_of, json_decode, memory_get_peak_usage, memory_get_usage, microtime, php_regex, + php_uname, posix_getuid, random_bytes, realpath, restore_error_handler, round, str_contains, + str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink, }; /// The PHP `Composer\Console\Application` and `Symfony\Component\Console\Application` are @@ -2067,28 +2067,20 @@ impl ApplicationHandle { } // prompt user for dir change if no composer.json is present in current dir - let no_composer_json_commands = vec![ - "".to_string(), - "list".to_string(), - "init".to_string(), - "about".to_string(), - "help".to_string(), - "diagnose".to_string(), - "self-update".to_string(), - "global".to_string(), - "create-project".to_string(), - "outdated".to_string(), - ]; let use_parent_dir_if_no_json_available = application.borrow().get_use_parent_dir_config_value(); - let no_composer_json_commands_pm: Vec<PhpMixed> = no_composer_json_commands - .iter() - .map(|s| PhpMixed::String(s.clone())) - .collect(); if new_work_dir.is_none() - && !in_array_strict( + && !matches!( command_name.as_deref().unwrap_or(""), - &no_composer_json_commands_pm, + "" | "list" + | "init" + | "about" + | "help" + | "diagnose" + | "self-update" + | "global" + | "create-project" + | "outdated" ) && !file_exists(Factory::get_composer_file().unwrap_or_default()) && use_parent_dir_if_no_json_available.as_bool() != Some(false) @@ -2180,16 +2172,11 @@ impl ApplicationHandle { // avoid loading plugins/initializing the Composer instance earlier than necessary if no plugin command is needed // if showing the version, we never need plugin commands - let mnp_list = vec![ - PhpMixed::String("".to_string()), - PhpMixed::String("list".to_string()), - PhpMixed::String("help".to_string()), - ]; let may_need_plugin_command = !input .borrow() .has_parameter_option(PhpMixed::from(vec!["--version", "-V"]), false) && (command_name.is_none() - || in_array_strict(command_name.as_deref().unwrap_or(""), &mnp_list) + || matches!(command_name.as_deref().unwrap_or(""), "" | "list" | "help") || (command_name.as_deref() == Some("_complete") && !is_non_allowed_root)); let may_need_script_command = may_need_plugin_command |
