Skip to content

Commit

Permalink
perf(derive): Reuse allocations for external subcommands
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
epage committed May 20, 2022
1 parent d61552a commit 0628d04
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clap_derive/src/derives/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>()
Expand Down

0 comments on commit 0628d04

Please sign in to comment.