mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
perf: Extract non-generic part of App::new()
Saves 5K.
This commit is contained in:
parent
7774a8ee8a
commit
778bcf2ecc
1 changed files with 26 additions and 20 deletions
|
@ -116,27 +116,33 @@ impl<'help> App<'help> {
|
||||||
/// # ;
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<S: Into<String>>(name: S) -> Self {
|
pub fn new<S: Into<String>>(name: S) -> Self {
|
||||||
let name = name.into();
|
/// The actual implementation of `new`, non-generic to save code size.
|
||||||
|
///
|
||||||
App {
|
/// If we don't do this rustc will unnecessarily generate multiple versions
|
||||||
id: Id::from(&*name),
|
/// of this code.
|
||||||
name,
|
fn new_inner<'help>(name: String) -> App<'help> {
|
||||||
..Default::default()
|
App {
|
||||||
|
id: Id::from(&*name),
|
||||||
|
name,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.arg(
|
||||||
|
Arg::new("help")
|
||||||
|
.long("help")
|
||||||
|
.help("Print help information")
|
||||||
|
.global(true)
|
||||||
|
.generated(),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("version")
|
||||||
|
.long("version")
|
||||||
|
.help("Print version information")
|
||||||
|
.global(true)
|
||||||
|
.generated(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
.arg(
|
|
||||||
Arg::new("help")
|
new_inner(name.into())
|
||||||
.long("help")
|
|
||||||
.help("Print help information")
|
|
||||||
.global(true)
|
|
||||||
.generated(),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new("version")
|
|
||||||
.long("version")
|
|
||||||
.help("Print version information")
|
|
||||||
.global(true)
|
|
||||||
.generated(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds an [argument] to the list of valid possibilities.
|
/// Adds an [argument] to the list of valid possibilities.
|
||||||
|
|
Loading…
Reference in a new issue