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/config.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/config.rs')
| -rw-r--r-- | crates/shirabe/src/config.rs | 69 |
1 files changed, 17 insertions, 52 deletions
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index 5d0e1220..154fbd05 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -306,28 +306,24 @@ impl Config { }; for (key, val_box) in &config_section_map { let val = val_box.clone(); - if in_array_strict( - key.clone(), - &[ - PhpMixed::String("bitbucket-oauth".to_string()), - PhpMixed::String("github-oauth".to_string()), - PhpMixed::String("gitlab-oauth".to_string()), - PhpMixed::String("gitlab-token".to_string()), - PhpMixed::String("http-basic".to_string()), - PhpMixed::String("bearer".to_string()), - PhpMixed::String("client-certificate".to_string()), - PhpMixed::String("forgejo-token".to_string()), - ], + if matches!( + key.as_str(), + "bitbucket-oauth" + | "github-oauth" + | "gitlab-oauth" + | "gitlab-token" + | "http-basic" + | "bearer" + | "client-certificate" + | "forgejo-token" ) && self.config.contains_key(key) { let existing = self.config.get(key).cloned().unwrap_or(PhpMixed::Null); self.config .insert(key.clone(), array_merge(existing, val.clone())); self.set_source_of_config_value(&val, key, source); - } else if in_array_strict( - key.clone(), - &[PhpMixed::String("allow-plugins".to_string())], - ) && self.config.contains_key(key) + } else if key == "allow-plugins" + && self.config.contains_key(key) && is_array(self.config.get(key).unwrap_or(&PhpMixed::Null)) && is_array(&val) { @@ -339,13 +335,8 @@ impl Config { array_merge(array_merge(val.clone(), existing), val.clone()), ); self.set_source_of_config_value(&val, key, source); - } else if in_array_strict( - key.clone(), - &[ - PhpMixed::String("gitlab-domains".to_string()), - PhpMixed::String("github-domains".to_string()), - ], - ) && self.config.contains_key(key) + } else if matches!(key.as_str(), "gitlab-domains" | "github-domains") + && self.config.contains_key(key) { let existing = self.config.get(key).cloned().unwrap_or(PhpMixed::Null); let merged = array_merge(existing, val.clone()); @@ -768,16 +759,7 @@ impl Config { let env = self.get_composer_env("COMPOSER_DISCARD_CHANGES"); if !matches!(env, PhpMixed::Bool(false)) { let env_str = env.as_string().unwrap_or("").to_string(); - if !in_array_strict( - env_str.clone(), - &[ - PhpMixed::String("stash".to_string()), - PhpMixed::String("true".to_string()), - PhpMixed::String("false".to_string()), - PhpMixed::String("1".to_string()), - PhpMixed::String("0".to_string()), - ], - ) { + if !matches!(env_str.as_str(), "stash" | "true" | "false" | "1" | "0") { return Err(RuntimeException { message: format!( "Invalid value for COMPOSER_DISCARD_CHANGES: {}. Expected 1, 0, true, false or stash", @@ -897,13 +879,7 @@ impl Config { self.get_composer_env("COMPOSER_SECURITY_BLOCKING_ABANDONED"); if !matches!(block_abandoned_env, PhpMixed::Bool(false)) { let env_str = block_abandoned_env.as_string().unwrap_or("").to_string(); - if !in_array_strict( - env_str.clone(), - &[ - PhpMixed::String("0".to_string()), - PhpMixed::String("1".to_string()), - ], - ) { + if !matches!(env_str.as_str(), "0" | "1") { return Err(RuntimeException { message: format!( "Invalid value for COMPOSER_SECURITY_BLOCKING_ABANDONED: {}. Expected 0 or 1.", @@ -1083,18 +1059,7 @@ impl Config { let hostname = parse_url(url, PHP_URL_HOST) .as_string() .map(|s| s.to_string()); - if in_array_strict( - scheme - .clone() - .map(PhpMixed::String) - .unwrap_or(PhpMixed::Null), - &[ - PhpMixed::String("http".to_string()), - PhpMixed::String("git".to_string()), - PhpMixed::String("ftp".to_string()), - PhpMixed::String("svn".to_string()), - ], - ) { + if matches!(scheme.as_deref(), Some("http" | "git" | "ftp" | "svn")) { if self.get_with_flags("secure-http", 0)?.as_bool() == Some(true) { if scheme.as_deref() == Some("svn") { if in_array_strict( |
