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) --- .../console/descriptor/application_description.rs | 7 +-- .../symfony/console/descriptor/json_descriptor.rs | 64 +++++++--------------- .../symfony/console/descriptor/text_descriptor.rs | 12 ++-- 3 files changed, 28 insertions(+), 55 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/descriptor') diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs index d30e6ad..33f6a8e 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs @@ -136,12 +136,7 @@ impl ApplicationDescription { entry.insert("id".to_string(), PhpMixed::String(namespace.clone())); entry.insert( "commands".to_string(), - PhpMixed::List( - names - .into_iter() - .map(|n| Box::new(PhpMixed::String(n))) - .collect(), - ), + PhpMixed::List(names.into_iter().map(PhpMixed::String).collect()), ); self.namespaces.as_mut().unwrap().insert(namespace, entry); } diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs index 9068a0a..381ee69 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs @@ -75,7 +75,7 @@ impl JsonDescriptor { }; let mut description = ApplicationDescription::new(application.clone(), described_namespace.clone(), true); - let mut commands: Vec> = vec![]; + let mut commands: Vec = vec![]; let short = matches!(options.get("short"), Some(PhpMixed::Bool(true))); let command_list: Vec<_> = description @@ -84,25 +84,24 @@ impl JsonDescriptor { .map(|c| c.borrow().clone_box()) .collect(); for mut command in command_list { - commands.push(Box::new(PhpMixed::Array( + commands.push(PhpMixed::Array( self.get_command_data(command.as_mut(), short)? .into_iter() - .map(|(k, v)| (k, Box::new(v))) .collect(), - ))); + )); } let mut data: IndexMap = IndexMap::new(); if "UNKNOWN" != application.borrow().get_name() { - let mut application_data: IndexMap> = IndexMap::new(); + let mut application_data: IndexMap = IndexMap::new(); application_data.insert( "name".to_string(), - Box::new(PhpMixed::String(application.borrow().get_name())), + PhpMixed::String(application.borrow().get_name()), ); if "UNKNOWN" != application.borrow().get_version() { application_data.insert( "version".to_string(), - Box::new(PhpMixed::String(application.borrow().get_version())), + PhpMixed::String(application.borrow().get_version()), ); } data.insert("application".to_string(), PhpMixed::Array(application_data)); @@ -122,11 +121,7 @@ impl JsonDescriptor { description .get_namespaces() .into_values() - .map(|ns| { - Box::new(PhpMixed::Array( - ns.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )) - }) + .map(|ns| PhpMixed::Array(ns.into_iter().collect())) .collect(), ), ); @@ -148,11 +143,8 @@ impl JsonDescriptor { }; self.write( - &shirabe_php_shim::json_encode_ex( - &PhpMixed::Array(data.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), - flags, - ) - .unwrap_or_default(), + &shirabe_php_shim::json_encode_ex(&PhpMixed::Array(data.into_iter().collect()), flags) + .unwrap_or_default(), false, ); Ok(()) @@ -258,39 +250,36 @@ impl JsonDescriptor { &self, definition: &InputDefinition, ) -> anyhow::Result> { - let mut input_arguments: IndexMap> = IndexMap::new(); + let mut input_arguments: IndexMap = IndexMap::new(); for (name, argument) in definition.get_arguments() { input_arguments.insert( name.clone(), - Box::new(PhpMixed::Array( + PhpMixed::Array( self.get_input_argument_data(argument)? .into_iter() - .map(|(k, v)| (k, Box::new(v))) .collect(), - )), + ), ); } - let mut input_options: IndexMap> = IndexMap::new(); + let mut input_options: IndexMap = IndexMap::new(); for (name, option) in definition.get_options() { input_options.insert( name.clone(), - Box::new(PhpMixed::Array( + PhpMixed::Array( self.get_input_option_data(option, false)? .into_iter() - .map(|(k, v)| (k, Box::new(v))) .collect(), - )), + ), ); if option.is_negatable() { input_options.insert( format!("no-{}", name), - Box::new(PhpMixed::Array( + PhpMixed::Array( self.get_input_option_data(option, true)? .into_iter() - .map(|(k, v)| (k, Box::new(v))) .collect(), - )), + ), ); } } @@ -326,26 +315,16 @@ impl JsonDescriptor { command .get_aliases() .into_iter() - .map(|a| Box::new(PhpMixed::String(a))) + .map(PhpMixed::String) .collect(), ), ); } else { command.merge_application_definition(false); - let mut usage = vec![Box::new(PhpMixed::String(command.get_synopsis(false)))]; - usage.extend( - command - .get_usages() - .into_iter() - .map(|u| Box::new(PhpMixed::String(u))), - ); - usage.extend( - command - .get_aliases() - .into_iter() - .map(|a| Box::new(PhpMixed::String(a))), - ); + let mut usage = vec![PhpMixed::String(command.get_synopsis(false))]; + usage.extend(command.get_usages().into_iter().map(PhpMixed::String)); + usage.extend(command.get_aliases().into_iter().map(PhpMixed::String)); data.insert("usage".to_string(), PhpMixed::List(usage)); data.insert( "help".to_string(), @@ -356,7 +335,6 @@ impl JsonDescriptor { PhpMixed::Array( self.get_input_definition_data(command.get_definition())? .into_iter() - .map(|(k, v)| (k, Box::new(v))) .collect(), ), ); diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs index 6590384..421cf52 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs @@ -342,7 +342,7 @@ impl TextDescriptor { for namespace in namespaces.values() { if let Some(PhpMixed::List(ns_commands)) = namespace.get("commands") { for c in ns_commands { - if let PhpMixed::String(name) = c.as_ref() + if let PhpMixed::String(name) = c && command_keys.contains(name) { merged.push(CommandOrString::String(name.clone())); @@ -369,7 +369,7 @@ impl TextDescriptor { let ns_commands: Vec = match namespace.get("commands") { Some(PhpMixed::List(names)) => names .iter() - .filter_map(|n| match n.as_ref() { + .filter_map(|n| match n { PhpMixed::String(name) if commands.contains_key(name) => { Some(name.clone()) } @@ -467,8 +467,8 @@ impl TextDescriptor { PhpMixed::Array(arr) => { let mut arr = arr.clone(); for (_key, value) in arr.iter_mut() { - if let PhpMixed::String(s) = value.as_ref() { - **value = PhpMixed::String(OutputFormatter::escape(s)?); + if let PhpMixed::String(s) = &*value { + *value = PhpMixed::String(OutputFormatter::escape(s)?); } } PhpMixed::Array(arr) @@ -476,8 +476,8 @@ impl TextDescriptor { PhpMixed::List(list) => { let mut list = list.clone(); for value in list.iter_mut() { - if let PhpMixed::String(s) = value.as_ref() { - **value = PhpMixed::String(OutputFormatter::escape(s)?); + if let PhpMixed::String(s) = &*value { + *value = PhpMixed::String(OutputFormatter::escape(s)?); } } PhpMixed::List(list) -- cgit v1.3.1