From 81b9fc9d92bb74aa8428ae4db39bd84e8c16095c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 20 Jun 2026 18:34:54 +0900 Subject: refactor(php-shim): drop Box wrapping from PhpMixed List/Array The List and Array variants of PhpMixed boxed their elements unnecessarily. Store PhpMixed values directly and update all callers accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/package/loader/array_loader.rs | 51 +++++++++-------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'crates/shirabe/src/package/loader/array_loader.rs') diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs index 889624d..0411645 100644 --- a/crates/shirabe/src/package/loader/array_loader.rs +++ b/crates/shirabe/src/package/loader/array_loader.rs @@ -92,14 +92,14 @@ impl CompleteOrRootPackage { fn php_to_map(value: &PhpMixed) -> IndexMap { match value { - PhpMixed::Array(m) => m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect(), + PhpMixed::Array(m) => m.clone(), _ => IndexMap::new(), } } fn php_to_string_vec(value: &PhpMixed) -> Vec { match value { - PhpMixed::List(l) => l.iter().map(|v| strval(v)).collect(), + PhpMixed::List(l) => l.iter().map(strval).collect(), PhpMixed::Array(m) => m.values().map(|v| strval(v)).collect(), _ => Vec::new(), } @@ -121,8 +121,8 @@ fn apply_link_setter(package: &mut Package, method: &str, links: IndexMap Vec { let entries: Vec<&PhpMixed> = match value { - PhpMixed::List(l) => l.iter().map(|v| v.as_ref()).collect(), - PhpMixed::Array(m) => m.values().map(|v| v.as_ref()).collect(), + PhpMixed::List(l) => l.iter().collect(), + PhpMixed::Array(m) => m.values().collect(), _ => Vec::new(), }; entries @@ -180,10 +180,7 @@ impl LoaderInterface for ArrayLoader { package.get_pretty_version(), opts.method, match entry.unwrap() { - PhpMixed::Array(arr) => arr - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(), + PhpMixed::Array(arr) => arr.clone(), _ => IndexMap::new(), }, )?; @@ -231,13 +228,7 @@ impl ArrayLoader { return Err(UnexpectedValueException { message: format!( "Unknown package has no name defined ({}).", - json_encode(&PhpMixed::Array( - config - .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), - )) - .unwrap_or_default() + json_encode(&PhpMixed::Array(config.clone())).unwrap_or_default() ), code: 0, } @@ -347,18 +338,18 @@ impl ArrayLoader { if let Some(bin) = config.get("bin").cloned() { let mut bin_list = match bin { PhpMixed::Array(_) | PhpMixed::List(_) => bin, - other => PhpMixed::List(vec![Box::new(other)]), + other => PhpMixed::List(vec![other]), }; if let PhpMixed::List(ref mut list) = bin_list { for item in list.iter_mut() { if let Some(s) = item.as_string() { - **item = PhpMixed::String(ltrim(s, Some("/"))); + *item = PhpMixed::String(ltrim(s, Some("/"))); } } } else if let PhpMixed::Array(ref mut map) = bin_list { for (_k, v) in map.iter_mut() { if let Some(s) = v.as_string() { - **v = PhpMixed::String(ltrim(s, Some("/"))); + *v = PhpMixed::String(ltrim(s, Some("/"))); } } } @@ -477,7 +468,7 @@ impl ArrayLoader { if let Some(r) = reason.as_string() && trim(r, None) == "self.version" { - **reason = PhpMixed::String(package.get_pretty_version().to_string()); + *reason = PhpMixed::String(package.get_pretty_version().to_string()); let _ = target; } } @@ -553,9 +544,9 @@ impl ArrayLoader { && let PhpMixed::Array(mut scripts_map) = scripts { for (event, listeners) in scripts_map.iter_mut() { - let listeners_array = match listeners.as_ref() { + let listeners_array = match &*listeners { PhpMixed::Array(_) | PhpMixed::List(_) => listeners.clone(), - other => Box::new(PhpMixed::List(vec![Box::new(other.clone())])), + other => PhpMixed::List(vec![other.clone()]), }; *listeners = listeners_array; let _ = event; @@ -602,7 +593,7 @@ impl ArrayLoader { && matches!(keywords, PhpMixed::Array(_) | PhpMixed::List(_)) { let keywords_vec: Vec = match keywords { - PhpMixed::List(list) => list.iter().map(|v| strval(v)).collect(), + PhpMixed::List(list) => list.iter().map(strval).collect(), PhpMixed::Array(map) => map.values().map(|v| strval(v)).collect(), _ => vec![], }; @@ -632,7 +623,7 @@ impl ArrayLoader { { let authors_vec: Vec> = list .iter() - .filter_map(|v| match v.as_ref() { + .filter_map(|v| match v { PhpMixed::Array(m) => Some( m.iter() .map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string())) @@ -660,10 +651,8 @@ impl ArrayLoader { { let funding_vec: Vec> = list .iter() - .filter_map(|v| match v.as_ref() { - PhpMixed::Array(m) => { - Some(m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) - } + .filter_map(|v| match v { + PhpMixed::Array(m) => Some(m.clone()), _ => None, }) .collect(); @@ -722,9 +711,7 @@ impl ArrayLoader { if let Some(entry) = config.get(*r#type) { let mut links: IndexMap = IndexMap::new(); let entries: IndexMap = match entry { - PhpMixed::Array(m) => { - m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect() - } + PhpMixed::Array(m) => m.clone(), _ => continue, }; for (pretty_target, constraint) in entries { @@ -892,8 +879,8 @@ impl ArrayLoader { PhpMixed::Array(m) => m.get("branch-alias").cloned(), _ => None, }) - .and_then(|v| match v.as_ref() { - PhpMixed::Array(m) => Some(m.clone()), + .and_then(|v| match v { + PhpMixed::Array(m) => Some(m), _ => None, }); -- cgit v1.3.1