From d9dca94603766712b5989ea8169c9e286d27a60c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 10:37:12 +0900 Subject: refactor(php-shim): take &str and return String from pathinfo pathinfo only ever receives a string and only ever returns one for the single-component options it supports, so the PhpMixed wrapping forced every call site to pack and unpack the value again. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/class_map_generator.rs | 17 +++++--------- .../src/symfony/process/executable_finder.rs | 26 ++++++++-------------- crates/shirabe-php-shim/src/fs.rs | 8 +++---- crates/shirabe/src/downloader/file_downloader.rs | 18 +++++---------- crates/shirabe/src/downloader/gzip_downloader.rs | 11 ++++----- crates/shirabe/src/factory.rs | 11 ++------- 6 files changed, 29 insertions(+), 62 deletions(-) diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs index 9fa37246..0f98ca27 100644 --- a/crates/shirabe-class-map-generator/src/class_map_generator.rs +++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs @@ -8,9 +8,9 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::symfony::finder::Finder; use shirabe_php_shim::{ DIRECTORY_SEPARATOR, InvalidArgumentException, LogicException, PATHINFO_EXTENSION, PHP_INT_MAX, - PhpMixed, RuntimeException, explode, getcwd, implode, in_array_strict, is_dir, is_file, - pathinfo, php_regex, preg_quote, realpath, str_replace, str_starts_with, stream_get_wrappers, - strlen, strpos, strrpos, strtr, substr, + RuntimeException, explode, getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_quote, + realpath, str_replace, str_starts_with, stream_get_wrappers, strlen, strpos, strrpos, strtr, + substr, }; use std::path::PathBuf; @@ -137,15 +137,8 @@ impl ClassMapGenerator { })); } }; - let ext = pathinfo(PhpMixed::String(file_path.clone()), PATHINFO_EXTENSION); - if !in_array_strict( - ext, - &self - .extensions - .iter() - .map(|e| PhpMixed::String(e.clone())) - .collect::>(), - ) { + let ext = pathinfo(&file_path, PATHINFO_EXTENSION); + if !self.extensions.contains(&ext) { continue; } diff --git a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs index d4891af0..3c44b4ad 100644 --- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs +++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs @@ -1,7 +1,5 @@ //! ref: composer/vendor/symfony/process/ExecutableFinder.php -use shirabe_php_shim::PhpMixed; - const CMD_BUILTINS: &[&str] = &[ "assoc", "break", "call", "cd", "chdir", "cls", "color", "copy", "date", "del", "dir", "echo", "endlocal", "erase", "exit", "for", "ftype", "goto", "help", "if", "label", "md", "mkdir", @@ -58,21 +56,15 @@ impl ExecutableFinder { }; suffixes.extend(exts); } - suffixes = if !shirabe_php_shim::pathinfo( - PhpMixed::String(name.to_string()), - shirabe_php_shim::PATHINFO_EXTENSION, - ) - .as_string() - .unwrap_or("") - .is_empty() - { - let mut s = vec![String::new()]; - s.extend(suffixes); - s - } else { - suffixes.push(String::new()); - suffixes - }; + suffixes = + if !shirabe_php_shim::pathinfo(name, shirabe_php_shim::PATHINFO_EXTENSION).is_empty() { + let mut s = vec![String::new()]; + s.extend(suffixes); + s + } else { + suffixes.push(String::new()); + suffixes + }; for suffix in &suffixes { for dir in &dirs { let dir = if dir.is_empty() { "." } else { dir.as_str() }; diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs index ac7a4f99..c3f131b3 100644 --- a/crates/shirabe-php-shim/src/fs.rs +++ b/crates/shirabe-php-shim/src/fs.rs @@ -1075,9 +1075,8 @@ pub fn opendir(path: impl AsRef) -> Option { }) } -pub fn pathinfo(path: PhpMixed, option: i64) -> PhpMixed { - let path = path.as_string().unwrap_or(""); - let component = match option { +pub fn pathinfo(path: &str, option: i64) -> String { + match option { PATHINFO_DIRNAME => dirname(path), PATHINFO_BASENAME => basename(path), PATHINFO_EXTENSION => { @@ -1095,8 +1094,7 @@ pub fn pathinfo(path: PhpMixed, option: i64) -> PhpMixed { } } _ => unreachable!("pathinfo called with an unsupported single-component option"), - }; - PhpMixed::String(component) + } } // TODO(phase-c): returns Option diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs index c5dfc5f7..4ee580f8 100644 --- a/crates/shirabe/src/downloader/file_downloader.rs +++ b/crates/shirabe/src/downloader/file_downloader.rs @@ -712,20 +712,14 @@ impl FileDownloader { impl FileDownloader { fn get_dist_path(&self, package: PackageInterfaceHandle, component: i64) -> String { pathinfo( - PhpMixed::String( - parse_url( - &strtr(&package.get_dist_url().unwrap_or_default(), "\\", "/"), - PHP_URL_PATH, - ) - .as_string() - .unwrap_or("") - .to_string(), - ), + parse_url( + &strtr(&package.get_dist_url().unwrap_or_default(), "\\", "/"), + PHP_URL_PATH, + ) + .as_string() + .unwrap_or(""), component, ) - .as_string() - .unwrap_or("") - .to_string() } pub(crate) fn clear_last_cache_write(&self, package: PackageInterfaceHandle) { diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs index 70b9f7bb..297cbc11 100644 --- a/crates/shirabe/src/downloader/gzip_downloader.rs +++ b/crates/shirabe/src/downloader/gzip_downloader.rs @@ -84,15 +84,12 @@ impl ArchiveDownloader for GzipDownloader { parse_url( &strtr(&package.get_dist_url().unwrap_or_default(), "\\", "/"), PHP_URL_PATH, - ), + ) + .as_string() + .unwrap_or(""), PATHINFO_FILENAME, ); - let target_filepath = format!( - "{}{}{}", - path, - DIRECTORY_SEPARATOR, - filename.as_string().unwrap_or_default() - ); + let target_filepath = format!("{}{}{}", path, DIRECTORY_SEPARATOR, filename); if !Platform::is_windows() { let command = vec![ diff --git a/crates/shirabe/src/factory.rs b/crates/shirabe/src/factory.rs index de632143..7328bf42 100644 --- a/crates/shirabe/src/factory.rs +++ b/crates/shirabe/src/factory.rs @@ -375,15 +375,8 @@ impl Factory { } pub fn get_lock_file(composer_file: &str) -> String { - let ext = pathinfo( - PhpMixed::String(composer_file.to_string()), - PATHINFO_EXTENSION, - ); - let is_json = match ext { - PhpMixed::String(s) => s == "json", - _ => false, - }; - if is_json { + let ext = pathinfo(composer_file, PATHINFO_EXTENSION); + if ext == "json" { format!( "{}lock", substr(composer_file, 0, Some(composer_file.len() as i64 - 4)) -- cgit v1.3.1