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/util/auth_helper.rs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'crates/shirabe/src/util/auth_helper.rs') diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index 80852bb2..c779a1bb 100644 --- a/crates/shirabe/src/util/auth_helper.rs +++ b/crates/shirabe/src/util/auth_helper.rs @@ -249,13 +249,9 @@ impl AuthHelper { .and_then(|a| a.get("password")) .and_then(|v| v.clone()) .unwrap_or_default(); - if in_array_strict( - password, - &[ - PhpMixed::String("gitlab-ci-token".to_string()), - PhpMixed::String("private-token".to_string()), - PhpMixed::String("oauth2".to_string()), - ], + if matches!( + password.as_str(), + "gitlab-ci-token" | "private-token" | "oauth2" ) { return Err(TransportException::new( format!("Invalid credentials for '{}', aborting.", url), @@ -520,13 +516,9 @@ impl AuthHelper { authentication_display_message = Some("Using GitHub token authentication".to_string()); } - } else if in_array_strict( - password.clone(), - &[ - PhpMixed::String("oauth2".to_string()), - PhpMixed::String("private-token".to_string()), - PhpMixed::String("gitlab-ci-token".to_string()), - ], + } else if matches!( + password.as_str(), + "oauth2" | "private-token" | "gitlab-ci-token" ) && in_array_strict(origin.to_string(), &{ let gitlab_domains = self.config.borrow_mut().get("gitlab-domains"); match &gitlab_domains { @@ -593,13 +585,7 @@ impl AuthHelper { .insert(origin.to_string(), display_message.clone()); } } - } else if in_array_strict( - origin.to_string(), - &[ - PhpMixed::String("api.bitbucket.org".to_string()), - PhpMixed::String("api.github.com".to_string()), - ], - ) { + } else if matches!(origin, "api.bitbucket.org" | "api.github.com") { return self.add_authentication_options(options, &str_replace("api.", "", origin), url); } -- cgit v1.3.1