mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 15:27:16 +00:00
perf: Drop a dep for faster builds
`OnceLock` became available as of 1.70 which is older than our new MSRV. We can easily get away without `Lazy` variants.
This commit is contained in:
parent
7126f78421
commit
087224a486
7 changed files with 37 additions and 63 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -483,7 +483,6 @@ dependencies = [
|
|||
"clap_builder 4.4.1",
|
||||
"clap_derive",
|
||||
"humantime",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"shlex",
|
||||
"snapbox",
|
||||
|
@ -523,7 +522,6 @@ dependencies = [
|
|||
"clap_lex 0.5.1",
|
||||
"color-print",
|
||||
"humantime",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"shlex",
|
||||
"snapbox",
|
||||
|
|
|
@ -86,7 +86,7 @@ suggestions = ["clap_builder/suggestions"]
|
|||
|
||||
# Optional
|
||||
deprecated = ["clap_builder/deprecated", "clap_derive?/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
|
||||
derive = ["dep:clap_derive", "dep:once_cell"]
|
||||
derive = ["dep:clap_derive"]
|
||||
cargo = ["clap_builder/cargo"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
|
||||
wrap_help = ["clap_builder/wrap_help"]
|
||||
env = ["clap_builder/env"] # Use environment variables during arg parsing
|
||||
|
@ -103,7 +103,6 @@ bench = false
|
|||
[dependencies]
|
||||
clap_builder = { path = "./clap_builder", version = "=4.4.1", default-features = false }
|
||||
clap_derive = { path = "./clap_derive", version = "=4.4.0", optional = true }
|
||||
once_cell = { version = "1.12.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = "1.0.82"
|
||||
|
|
|
@ -44,7 +44,7 @@ suggestions = ["dep:strsim", "error-context"]
|
|||
|
||||
# Optional
|
||||
deprecated = [] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
|
||||
cargo = ["dep:once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
|
||||
cargo = [] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
|
||||
wrap_help = ["help", "dep:terminal_size"]
|
||||
env = [] # Use environment variables during arg parsing
|
||||
unicode = ["dep:unicode-width", "dep:unicase"] # Support for unicode characters in arguments and help messages
|
||||
|
@ -66,7 +66,6 @@ anstyle = "1.0.0"
|
|||
terminal_size = { version = "0.2.1", optional = true }
|
||||
backtrace = { version = "0.3.67", optional = true }
|
||||
unicode-width = { version = "0.1.9", optional = true }
|
||||
once_cell = { version = "1.12.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = "1.0.82"
|
||||
|
|
|
@ -48,13 +48,6 @@ pub type Error = crate::error::Error<crate::error::DefaultFormatter>;
|
|||
|
||||
pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __macro_refs {
|
||||
#[cfg(feature = "cargo")]
|
||||
#[doc(hidden)]
|
||||
pub use once_cell;
|
||||
}
|
||||
|
||||
#[macro_use]
|
||||
#[allow(missing_docs)]
|
||||
mod macros;
|
||||
|
|
|
@ -44,9 +44,9 @@ macro_rules! crate_authors {
|
|||
($sep:expr) => {{
|
||||
static authors: &str = env!("CARGO_PKG_AUTHORS");
|
||||
if authors.contains(':') {
|
||||
static CACHED: clap::__macro_refs::once_cell::sync::Lazy<String> =
|
||||
clap::__macro_refs::once_cell::sync::Lazy::new(|| authors.replace(':', $sep));
|
||||
let s: &'static str = &*CACHED;
|
||||
static CACHED: std::sync::OnceLock<String> = std::sync::OnceLock::new();
|
||||
let s = CACHED.get_or_init(|| authors.replace(':', $sep));
|
||||
let s: &'static str = &*s;
|
||||
s
|
||||
} else {
|
||||
authors
|
||||
|
|
|
@ -575,20 +575,22 @@ impl Item {
|
|||
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
|
||||
{
|
||||
quote_spanned!(attr.name.clone().span()=> {
|
||||
static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy<String> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
static DEFAULT_VALUE: ::std::sync::OnceLock<String> = ::std::sync::OnceLock::new();
|
||||
let s = DEFAULT_VALUE.get_or_init(|| {
|
||||
let val: #ty = #val;
|
||||
clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned()
|
||||
});
|
||||
let s: &'static str = &*DEFAULT_VALUE;
|
||||
let s: &'static str = &*s;
|
||||
s
|
||||
})
|
||||
} else {
|
||||
quote_spanned!(attr.name.clone().span()=> {
|
||||
static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy<String> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
static DEFAULT_VALUE: ::std::sync::OnceLock<String> = ::std::sync::OnceLock::new();
|
||||
let s = DEFAULT_VALUE.get_or_init(|| {
|
||||
let val: #ty = #val;
|
||||
::std::string::ToString::to_string(&val)
|
||||
});
|
||||
let s: &'static str = &*DEFAULT_VALUE;
|
||||
let s: &'static str = &*s;
|
||||
s
|
||||
})
|
||||
};
|
||||
|
@ -643,14 +645,11 @@ impl Item {
|
|||
})
|
||||
}
|
||||
|
||||
static DEFAULT_STRINGS: clap::__derive_refs::once_cell::sync::Lazy<Vec<::std::string::String>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
iter_to_vals(#expr).collect()
|
||||
});
|
||||
|
||||
static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
|
||||
});
|
||||
DEFAULT_VALUES.iter().copied()
|
||||
static DEFAULT_STRINGS: ::std::sync::OnceLock<Vec<String>> = ::std::sync::OnceLock::new();
|
||||
static DEFAULT_VALUES: ::std::sync::OnceLock<Vec<&str>> = ::std::sync::OnceLock::new();
|
||||
DEFAULT_VALUES.get_or_init(|| {
|
||||
DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::string::String::as_str).collect()
|
||||
}).iter().copied()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -663,14 +662,11 @@ impl Item {
|
|||
iterable.into_iter().map(|val| val.borrow().to_string())
|
||||
}
|
||||
|
||||
static DEFAULT_STRINGS: clap::__derive_refs::once_cell::sync::Lazy<Vec<::std::string::String>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
iter_to_vals(#expr).collect()
|
||||
});
|
||||
|
||||
static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
|
||||
});
|
||||
DEFAULT_VALUES.iter().copied()
|
||||
static DEFAULT_STRINGS: ::std::sync::OnceLock<Vec<String>> = ::std::sync::OnceLock::new();
|
||||
static DEFAULT_VALUES: ::std::sync::OnceLock<Vec<&str>> = ::std::sync::OnceLock::new();
|
||||
DEFAULT_VALUES.get_or_init(|| {
|
||||
DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::string::String::as_str).collect()
|
||||
}).iter().copied()
|
||||
}
|
||||
})
|
||||
};
|
||||
|
@ -707,20 +703,22 @@ impl Item {
|
|||
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
|
||||
{
|
||||
quote_spanned!(attr.name.clone().span()=> {
|
||||
static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
static DEFAULT_VALUE: ::std::sync::OnceLock<String> = ::std::sync::OnceLock::new();
|
||||
let s = DEFAULT_VALUE.get_or_init(|| {
|
||||
let val: #ty = #val;
|
||||
clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned()
|
||||
});
|
||||
let s: &'static ::std::ffi::OsStr = &*DEFAULT_VALUE;
|
||||
let s: &'static str = &*s;
|
||||
s
|
||||
})
|
||||
} else {
|
||||
quote_spanned!(attr.name.clone().span()=> {
|
||||
static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
static DEFAULT_VALUE: ::std::sync::OnceLock<::std::ffi::OsString> = ::std::sync::OnceLock::new();
|
||||
let s = DEFAULT_VALUE.get_or_init(|| {
|
||||
let val: #ty = #val;
|
||||
::std::ffi::OsString::from(val)
|
||||
});
|
||||
let s: &'static ::std::ffi::OsStr = &*DEFAULT_VALUE;
|
||||
let s: &'static ::std::ffi::OsStr = &*s;
|
||||
s
|
||||
})
|
||||
};
|
||||
|
@ -775,14 +773,11 @@ impl Item {
|
|||
})
|
||||
}
|
||||
|
||||
static DEFAULT_OS_STRINGS: clap::__derive_refs::once_cell::sync::Lazy<Vec<::std::ffi::OsString>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
iter_to_vals(#expr).collect()
|
||||
});
|
||||
|
||||
static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
|
||||
});
|
||||
DEFAULT_VALUES.iter().copied()
|
||||
static DEFAULT_STRINGS: ::std::sync::OnceLock<Vec<::std::ffi::OsString>> = ::std::sync::OnceLock::new();
|
||||
static DEFAULT_VALUES: ::std::sync::OnceLock<Vec<&::std::ffi::OsStr>> = ::std::sync::OnceLock::new();
|
||||
DEFAULT_VALUES.get_or_init(|| {
|
||||
DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::ffi::OsString::as_os_str).collect()
|
||||
}).iter().copied()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -795,14 +790,11 @@ impl Item {
|
|||
iterable.into_iter().map(|val| val.borrow().into())
|
||||
}
|
||||
|
||||
static DEFAULT_OS_STRINGS: clap::__derive_refs::once_cell::sync::Lazy<Vec<::std::ffi::OsString>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
iter_to_vals(#expr).collect()
|
||||
});
|
||||
|
||||
static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__derive_refs::once_cell::sync::Lazy::new(|| {
|
||||
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
|
||||
});
|
||||
DEFAULT_VALUES.iter().copied()
|
||||
static DEFAULT_STRINGS: ::std::sync::OnceLock<Vec<::std::ffi::OsString>> = ::std::sync::OnceLock::new();
|
||||
static DEFAULT_VALUES: ::std::sync::OnceLock<Vec<&::std::ffi::OsStr>> = ::std::sync::OnceLock::new();
|
||||
DEFAULT_VALUES.get_or_init(|| {
|
||||
DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::ffi::OsString::as_os_str).collect()
|
||||
}).iter().copied()
|
||||
}
|
||||
})
|
||||
};
|
||||
|
|
|
@ -111,10 +111,3 @@ pub mod _faq;
|
|||
pub mod _features;
|
||||
#[cfg(feature = "unstable-doc")]
|
||||
pub mod _tutorial;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[cfg(feature = "derive")]
|
||||
pub mod __derive_refs {
|
||||
#[doc(hidden)]
|
||||
pub use once_cell;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue