From 0421613f32bfda4cd4049ea16e8e7e31061b9932 Mon Sep 17 00:00:00 2001 From: Haydon Ryan <6804348+haydonryan@users.noreply.github.com> Date: Sat, 15 Aug 2026 20:20:33 -0500 Subject: [PATCH] args_info: call get_args_info once per enum variant For each variant of a subcommand enum, the generated ArgsInfo::get_args_info previously called ::get_args_info() twice (once for .name, once for .command), constructing a full CommandInfoWithArgs twice and discarding one. Call it once and reuse for both fields. This halves the per-variant construction work and, since get_args_info is inlined, removes a full duplicated CommandInfoWithArgs construction + drop from the emitted machine code. Behavior is identical. --- argh_derive/src/args_info.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/argh_derive/src/args_info.rs b/argh_derive/src/args_info.rs index 7e5a0dd..b0c7410 100644 --- a/argh_derive/src/args_info.rs +++ b/argh_derive/src/args_info.rs @@ -161,9 +161,12 @@ fn impl_arg_info_enum( let variant_ty_info = variants.iter().map(|t| { let ty = t.ty; quote!( - argh::SubCommandInfo { - name: #ty::get_args_info().name, - command: #ty::get_args_info() + { + let __arg_info = #ty::get_args_info(); + argh::SubCommandInfo { + name: __arg_info.name, + command: __arg_info, + } } ) });