Skip to content

Commit

Permalink
Merge pull request #4783 from epage/perf
Browse files Browse the repository at this point in the history
perf(derive): Reduce the amount of generated code
  • Loading branch information
epage committed Mar 24, 2023
2 parents 240e237 + 7e7a45a commit e626dd4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions clap_derive/src/item.rs
Expand Up @@ -277,6 +277,10 @@ impl Item {
}

fn push_method(&mut self, kind: AttrKind, name: Ident, arg: impl ToTokens) {
self.push_method_(kind, name, arg.to_token_stream());
}

fn push_method_(&mut self, kind: AttrKind, name: Ident, arg: TokenStream) {
if name == "id" {
match kind {
AttrKind::Command | AttrKind::Value => {
Expand All @@ -293,7 +297,7 @@ impl Item {
}
AttrKind::Group | AttrKind::Arg | AttrKind::Clap | AttrKind::StructOpt => {}
}
self.name = Name::Assigned(quote!(#arg));
self.name = Name::Assigned(arg);
} else if name == "name" {
match kind {
AttrKind::Arg => {
Expand All @@ -315,16 +319,16 @@ impl Item {
| AttrKind::Clap
| AttrKind::StructOpt => {}
}
self.name = Name::Assigned(quote!(#arg));
self.name = Name::Assigned(arg);
} else if name == "value_parser" {
self.value_parser = Some(ValueParser::Explicit(Method::new(name, quote!(#arg))));
self.value_parser = Some(ValueParser::Explicit(Method::new(name, arg)));
} else if name == "action" {
self.action = Some(Action::Explicit(Method::new(name, quote!(#arg))));
self.action = Some(Action::Explicit(Method::new(name, arg)));
} else {
if name == "short" || name == "long" {
self.is_positional = false;
}
self.methods.push(Method::new(name, quote!(#arg)));
self.methods.push(Method::new(name, arg));
}
}

Expand Down

0 comments on commit e626dd4

Please sign in to comment.