Skip to content

Commit

Permalink
perf(derive): Cache positional status
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 7, 2022
1 parent 7980c5c commit efc1520
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions clap_derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Attrs {
next_help_heading: Option<Method>,
help_heading: Option<Method>,
is_enum: bool,
is_positional: bool,
kind: Sp<Kind>,
}

Expand Down Expand Up @@ -436,6 +437,7 @@ impl Attrs {
next_help_heading: None,
help_heading: None,
is_enum: false,
is_positional: true,
kind: Sp::new(Kind::Arg(Sp::new(Ty::Other, default_span)), default_span),
}
}
Expand All @@ -448,6 +450,9 @@ impl Attrs {
} else if name == "action" {
self.action = Some(Action::Explicit(Method::new(name, quote!(#arg))));
} else {
if name == "short" || name == "long" {
self.is_positional = false;
}
self.methods.push(Method::new(name, quote!(#arg)));
}
}
Expand Down Expand Up @@ -810,6 +815,10 @@ impl Attrs {
self.is_enum
}

pub fn is_positional(&self) -> bool {
self.is_positional
}

pub fn ignore_case(&self) -> TokenStream {
let method = self.find_method("ignore_case");

Expand All @@ -828,12 +837,6 @@ impl Attrs {
self.env_casing.clone()
}

pub fn is_positional(&self) -> bool {
self.methods
.iter()
.all(|m| m.name != "long" && m.name != "short")
}

pub fn has_explicit_methods(&self) -> bool {
self.methods
.iter()
Expand Down

0 comments on commit efc1520

Please sign in to comment.