perf(derive): Reuse allocations for external subcommands

In case the `ArgMatches` is cloned, this forces a constraint that the
underlying type impls `Clone` but that should be safe as we only support
`String` and `OsString`.
This commit is contained in:
Ed Page 2022-05-20 12:02:29 -05:00
parent d61552a8b8
commit 0628d04174

View file

@ -527,9 +527,10 @@ fn gen_from_arg_matches(
::std::iter::once(#str_ty::from(#subcommand_name_var))
.chain(
#sub_arg_matches_var
.get_many::<#str_ty>("")
.remove_many::<#str_ty>("")
.expect("unexpected type")
.into_iter().flatten() // `""` isn't present, bug in `unstable-v4`
.map(|f| ::std::sync::Arc::try_unwrap(f).unwrap_or_else(|arc| (*arc).clone()))
.map(#str_ty::from)
)
.collect::<::std::vec::Vec<_>>()