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/repository/vcs/gitlab_driver.rs | 39 ++++++---------------- 1 file changed, 10 insertions(+), 29 deletions(-) (limited to 'crates/shirabe/src/repository/vcs/gitlab_driver.rs') diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 8f49e8ef..5fe513f6 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -18,8 +18,8 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed, - array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, - in_array_strict, is_array, is_string, ord, php_regex, strpos, strtolower, + array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, is_array, + is_string, ord, php_regex, strpos, strtolower, }; /// Driver for GitLab API, use the Git driver for local checkouts. @@ -115,13 +115,7 @@ impl GitLabDriver { .get(&CaptureKey::ByName("scheme".to_string())) .cloned() .unwrap_or_default(); - self.scheme = if in_array_strict( - scheme_match.clone(), - &[ - PhpMixed::String("https".to_string()), - PhpMixed::String("http".to_string()), - ], - ) { + self.scheme = if matches!(scheme_match.as_str(), "https" | "http") { scheme_match } else if self .inner @@ -158,14 +152,7 @@ impl GitLabDriver { .filter(|_| is_string(&protocol_value)) { // https treated as a synonym for http. - if !in_array_strict( - protocol.to_string(), - &[ - PhpMixed::String("git".to_string()), - PhpMixed::String("http".to_string()), - PhpMixed::String("https".to_string()), - ], - ) { + if !matches!(protocol, "git" | "http" | "https") { return Err(RuntimeException { message: "gitlab-protocol must be one of git, http.".to_string(), code: 0, @@ -601,18 +588,12 @@ impl GitLabDriver { let bytes: Vec = string.chars().collect(); for byte in &bytes { let character = byte.to_string(); - let final_character = if !ctype_alnum(&character) - && !in_array_strict( - character.clone(), - &[ - PhpMixed::String("-".to_string()), - PhpMixed::String("_".to_string()), - ], - ) { - format!("%{:02X}", ord(&character)) - } else { - character - }; + let final_character = + if !ctype_alnum(&character) && !matches!(character.as_str(), "-" | "_") { + format!("%{:02X}", ord(&character)) + } else { + character + }; encoded.push_str(&final_character); } -- cgit v1.3.1