Skip to content

Commit dbf2c86

Browse files
committed
perf: Misc simplifications for code size
This dropped a fraction of a KiB but it will at least not cause people to ask if it'd help to simplify in the future.
1 parent 14c6ce0 commit dbf2c86

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

src/builder/arg.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Arg {
146146
#[must_use]
147147
pub fn short(mut self, s: impl IntoResettable<char>) -> Self {
148148
if let Some(s) = s.into_resettable().into_option() {
149-
assert!(s != '-', "short option name cannot be `-`");
149+
debug_assert!(s != '-', "short option name cannot be `-`");
150150
self.short = Some(s);
151151
} else {
152152
self.short = None;
@@ -241,7 +241,7 @@ impl Arg {
241241
#[must_use]
242242
pub fn short_alias(mut self, name: impl IntoResettable<char>) -> Self {
243243
if let Some(name) = name.into_resettable().into_option() {
244-
assert!(name != '-', "short alias name cannot be `-`");
244+
debug_assert!(name != '-', "short alias name cannot be `-`");
245245
self.short_aliases.push((name, false));
246246
} else {
247247
self.short_aliases.clear();
@@ -301,7 +301,7 @@ impl Arg {
301301
#[must_use]
302302
pub fn short_aliases(mut self, names: impl IntoIterator<Item = char>) -> Self {
303303
for s in names {
304-
assert!(s != '-', "short alias name cannot be `-`");
304+
debug_assert!(s != '-', "short alias name cannot be `-`");
305305
self.short_aliases.push((s, false));
306306
}
307307
self
@@ -357,7 +357,7 @@ impl Arg {
357357
#[must_use]
358358
pub fn visible_short_alias(mut self, name: impl IntoResettable<char>) -> Self {
359359
if let Some(name) = name.into_resettable().into_option() {
360-
assert!(name != '-', "short alias name cannot be `-`");
360+
debug_assert!(name != '-', "short alias name cannot be `-`");
361361
self.short_aliases.push((name, true));
362362
} else {
363363
self.short_aliases.clear();
@@ -412,7 +412,7 @@ impl Arg {
412412
#[must_use]
413413
pub fn visible_short_aliases(mut self, names: impl IntoIterator<Item = char>) -> Self {
414414
for n in names {
415-
assert!(n != '-', "short alias name cannot be `-`");
415+
debug_assert!(n != '-', "short alias name cannot be `-`");
416416
self.short_aliases.push((n, true));
417417
}
418418
self

src/builder/command.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ impl Command {
195195
/// [arguments]: Arg
196196
#[must_use]
197197
pub fn args(mut self, args: impl IntoIterator<Item = impl Into<Arg>>) -> Self {
198-
let args = args.into_iter();
199-
let (lower, _) = args.size_hint();
200-
self.args.reserve(lower);
201-
202198
for arg in args {
203199
self = self.arg(arg);
204200
}
@@ -407,10 +403,6 @@ impl Command {
407403
/// [`IntoIterator`]: std::iter::IntoIterator
408404
#[must_use]
409405
pub fn subcommands(mut self, subcmds: impl IntoIterator<Item = impl Into<Self>>) -> Self {
410-
let subcmds = subcmds.into_iter();
411-
let (lower, _) = subcmds.size_hint();
412-
self.subcommands.reserve(lower);
413-
414406
for subcmd in subcmds {
415407
self = self.subcommand(subcmd);
416408
}
@@ -2219,7 +2211,7 @@ impl Command {
22192211
#[must_use]
22202212
pub fn short_flag_alias(mut self, name: impl IntoResettable<char>) -> Self {
22212213
if let Some(name) = name.into_resettable().into_option() {
2222-
assert!(name != '-', "short alias name cannot be `-`");
2214+
debug_assert!(name != '-', "short alias name cannot be `-`");
22232215
self.short_flag_aliases.push((name, false));
22242216
} else {
22252217
self.short_flag_aliases.clear();
@@ -2310,7 +2302,7 @@ impl Command {
23102302
#[must_use]
23112303
pub fn short_flag_aliases(mut self, names: impl IntoIterator<Item = char>) -> Self {
23122304
for s in names {
2313-
assert!(s != '-', "short alias name cannot be `-`");
2305+
debug_assert!(s != '-', "short alias name cannot be `-`");
23142306
self.short_flag_aliases.push((s, false));
23152307
}
23162308
self
@@ -2402,7 +2394,7 @@ impl Command {
24022394
#[must_use]
24032395
pub fn visible_short_flag_alias(mut self, name: impl IntoResettable<char>) -> Self {
24042396
if let Some(name) = name.into_resettable().into_option() {
2405-
assert!(name != '-', "short alias name cannot be `-`");
2397+
debug_assert!(name != '-', "short alias name cannot be `-`");
24062398
self.short_flag_aliases.push((name, true));
24072399
} else {
24082400
self.short_flag_aliases.clear();
@@ -2491,7 +2483,7 @@ impl Command {
24912483
#[must_use]
24922484
pub fn visible_short_flag_aliases(mut self, names: impl IntoIterator<Item = char>) -> Self {
24932485
for s in names {
2494-
assert!(s != '-', "short alias name cannot be `-`");
2486+
debug_assert!(s != '-', "short alias name cannot be `-`");
24952487
self.short_flag_aliases.push((s, true));
24962488
}
24972489
self
@@ -4041,7 +4033,7 @@ impl Command {
40414033
.map(|arg| arg.get_id().clone())
40424034
.collect();
40434035

4044-
assert!(args_missing_help.is_empty(),
4036+
debug_assert!(args_missing_help.is_empty(),
40454037
"Command::help_expected is enabled for the Command {}, but at least one of its arguments does not have either `help` or `long_help` set. List of such arguments: {}",
40464038
self.name,
40474039
args_missing_help.join(", ")
@@ -4299,7 +4291,7 @@ impl Command {
42994291

43004292
#[inline]
43014293
pub(crate) fn contains_short(&self, s: char) -> bool {
4302-
assert!(
4294+
debug_assert!(
43034295
self.is_set(AppSettings::Built),
43044296
"If Command::_build hasn't been called, manually search through Arg shorts"
43054297
);

src/mkeymap.rs

-5
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ impl MKeyMap {
9090
self.keys.iter().any(|x| x.key == key)
9191
}
9292

93-
/// Reserves capacity for at least additional more elements to be inserted
94-
pub(crate) fn reserve(&mut self, additional: usize) {
95-
self.args.reserve(additional);
96-
}
97-
9893
/// Push an argument in the map.
9994
pub(crate) fn push(&mut self, new_arg: Arg) {
10095
self.args.push(new_arg);

0 commit comments

Comments
 (0)