From 778bcf2eccb3a3efa6c528bc0cd0218329aa45cf Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Mon, 31 Jan 2022 00:18:55 +0100 Subject: [PATCH] perf: Extract non-generic part of App::new() Saves 5K. --- src/build/app/mod.rs | 46 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index 2ea76eee..440ae185 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -116,27 +116,33 @@ impl<'help> App<'help> { /// # ; /// ``` pub fn new>(name: S) -> Self { - let name = name.into(); - - App { - id: Id::from(&*name), - name, - ..Default::default() + /// The actual implementation of `new`, non-generic to save code size. + /// + /// If we don't do this rustc will unnecessarily generate multiple versions + /// of this code. + fn new_inner<'help>(name: String) -> App<'help> { + 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") - .long("help") - .help("Print help information") - .global(true) - .generated(), - ) - .arg( - Arg::new("version") - .long("version") - .help("Print version information") - .global(true) - .generated(), - ) + + new_inner(name.into()) } /// Adds an [argument] to the list of valid possibilities.