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/repository/vcs/gitlab_driver.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/repository/vcs/gitlab_driver.rs')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/gitlab_driver.rs | 39 |
1 files changed, 10 insertions, 29 deletions
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<char> = 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); } |
