mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Merge pull request #4783 from epage/perf
perf(derive): Reduce the amount of generated code
This commit is contained in:
commit
e626dd4ffc
1 changed files with 9 additions and 5 deletions
|
@ -277,6 +277,10 @@ impl Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_method(&mut self, kind: AttrKind, name: Ident, arg: impl ToTokens) {
|
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" {
|
if name == "id" {
|
||||||
match kind {
|
match kind {
|
||||||
AttrKind::Command | AttrKind::Value => {
|
AttrKind::Command | AttrKind::Value => {
|
||||||
|
@ -293,7 +297,7 @@ impl Item {
|
||||||
}
|
}
|
||||||
AttrKind::Group | AttrKind::Arg | AttrKind::Clap | AttrKind::StructOpt => {}
|
AttrKind::Group | AttrKind::Arg | AttrKind::Clap | AttrKind::StructOpt => {}
|
||||||
}
|
}
|
||||||
self.name = Name::Assigned(quote!(#arg));
|
self.name = Name::Assigned(arg);
|
||||||
} else if name == "name" {
|
} else if name == "name" {
|
||||||
match kind {
|
match kind {
|
||||||
AttrKind::Arg => {
|
AttrKind::Arg => {
|
||||||
|
@ -315,16 +319,16 @@ impl Item {
|
||||||
| AttrKind::Clap
|
| AttrKind::Clap
|
||||||
| AttrKind::StructOpt => {}
|
| AttrKind::StructOpt => {}
|
||||||
}
|
}
|
||||||
self.name = Name::Assigned(quote!(#arg));
|
self.name = Name::Assigned(arg);
|
||||||
} else if name == "value_parser" {
|
} 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" {
|
} else if name == "action" {
|
||||||
self.action = Some(Action::Explicit(Method::new(name, quote!(#arg))));
|
self.action = Some(Action::Explicit(Method::new(name, arg)));
|
||||||
} else {
|
} else {
|
||||||
if name == "short" || name == "long" {
|
if name == "short" || name == "long" {
|
||||||
self.is_positional = false;
|
self.is_positional = false;
|
||||||
}
|
}
|
||||||
self.methods.push(Method::new(name, quote!(#arg)));
|
self.methods.push(Method::new(name, arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue