Skip to content

Commit

Permalink
Merge #1735
Browse files Browse the repository at this point in the history
1735: Get rid of extra scopes r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <[email protected]>
  • Loading branch information
bors[bot] and CreepySkeleton authored Mar 9, 2020
2 parents 2370665 + 3e1f6ed commit bc738e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
20 changes: 8 additions & 12 deletions src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,12 +1408,9 @@ impl<'b> App<'b> {
self._build();
}

{
let mut parser = Parser::new(self);

// do the real parsing
parser.get_matches_with(&mut matcher, it)?;
}
// do the real parsing
let mut parser = Parser::new(self);
parser.get_matches_with(&mut matcher, it)?;

let global_arg_vec: Vec<Id> = self
.args
Expand All @@ -1438,13 +1435,12 @@ impl<'b> App<'b> {

self._derive_display_order();
self._create_help_and_version();

// Perform expensive debug assertions
debug_assert!({
for a in self.args.args.iter() {
self._arg_debug_asserts(a);
}
true
});
#[cfg(debug_assertions)]
for a in self.args.args.iter() {
self._arg_debug_asserts(a);
}

let mut pos_counter = 1;
for a in self.args.args.iter_mut() {
Expand Down
30 changes: 14 additions & 16 deletions src/mkeymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,20 @@ impl<'b> MKeyMap<'b> {
let positional;
let mut longs: Vec<_>;

{
let arg = &self.args[index];
short = arg.short.map(KeyType::Short);
positional = arg.index.map(KeyType::Position);

longs = arg
.aliases
.clone()
.map(|v| {
v.iter()
.map(|(n, _)| KeyType::Long(OsString::from(n)))
.collect()
})
.unwrap_or_default();
longs.extend(arg.long.map(|l| KeyType::Long(OsString::from(l))));
}
let arg = &self.args[index];
short = arg.short.map(KeyType::Short);
positional = arg.index.map(KeyType::Position);

longs = arg
.aliases
.clone()
.map(|v| {
v.iter()
.map(|(n, _)| KeyType::Long(OsString::from(n)))
.collect()
})
.unwrap_or_default();
longs.extend(arg.long.map(|l| KeyType::Long(OsString::from(l))));

if let Some(s) = short {
self.insert_key(s, index)
Expand Down
5 changes: 2 additions & 3 deletions src/parse/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ impl<'b, 'c, 'z> Validator<'b, 'c, 'z> {
self.p.add_defaults(matcher)?;
if let ParseResult::Opt(a) = needs_val_of {
debugln!("Validator::validate: needs_val_of={:?}", a);
{
self.validate_required(matcher)?;
}
self.validate_required(matcher)?;

let o = self.p.app.find(a).expect(INTERNAL_ERROR_MSG);
reqs_validated = true;
let should_err = if let Some(v) = matcher.0.args.get(&o.id) {
Expand Down

1 comment on commit bc738e1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: bc738e1 Previous: 2370665 Ratio
build_empty 105 ns/iter (+/- 1) 116 ns/iter (+/- 1) 0.91
parse_empty 1090 ns/iter (+/- 12) 1115 ns/iter (+/- 17) 0.98
parse_simple_with_complex 4056 ns/iter (+/- 53) 4371 ns/iter (+/- 60) 0.93
parse_simple_with_pos 3222 ns/iter (+/- 34) 3389 ns/iter (+/- 49) 0.95
parse_simple_with_opt 3412 ns/iter (+/- 47) 3526 ns/iter (+/- 62) 0.97
parse_simple_with_flag 2933 ns/iter (+/- 27) 3141 ns/iter (+/- 47) 0.93
build_with_pos_ref 270 ns/iter (+/- 2) 264 ns/iter (+/- 4) 1.0
build_with_pos 193 ns/iter (+/- 2) 198 ns/iter (+/- 2) 0.97
build_with_opt_ref 360 ns/iter (+/- 5) 399 ns/iter (+/- 5) 0.90
build_with_opt 298 ns/iter (+/- 4) 304 ns/iter (+/- 4) 0.98
build_with_flag_ref 314 ns/iter (+/- 5) 347 ns/iter (+/- 6) 0.90
build_with_flag 256 ns/iter (+/- 2) 267 ns/iter (+/- 4) 0.96
build_simple 769 ns/iter (+/- 10) 932 ns/iter (+/- 16) 0.83
build_from_usage 4608 ns/iter (+/- 63) 5141 ns/iter (+/- 69) 0.90
build_from_builder 2916 ns/iter (+/- 30) 2794 ns/iter (+/- 48) 1.0
build_from_macros 2710 ns/iter (+/- 36) 2840 ns/iter (+/- 39) 0.95
parse_complex 7976 ns/iter (+/- 202) 8470 ns/iter (+/- 149) 0.94
parse_complex_with_flag 9536 ns/iter (+/- 160) 10398 ns/iter (+/- 232) 0.92
parse_complex_with_opt 9545 ns/iter (+/- 178) 10362 ns/iter (+/- 222) 0.92
parse_complex_with_pos 9552 ns/iter (+/- 220) 10232 ns/iter (+/- 152) 0.93
parse_complex_with_sc 11229 ns/iter (+/- 125) 12100 ns/iter (+/- 185) 0.93
parse_complex_with_sc_flag 12581 ns/iter (+/- 127) 12939 ns/iter (+/- 233) 0.97
parse_complex_with_sc_opt 12418 ns/iter (+/- 186) 13255 ns/iter (+/- 227) 0.94
parse_complex_with_sc_pos 12154 ns/iter (+/- 182) 12401 ns/iter (+/- 353) 0.98
parse_complex1 14999 ns/iter (+/- 192) 16472 ns/iter (+/- 539) 0.91
parse_complex2 17195 ns/iter (+/- 206) 19249 ns/iter (+/- 565) 0.89
parse_args_negate_scs 17121 ns/iter (+/- 184) 17247 ns/iter (+/- 172) 0.99
parse_complex_with_sc_complex 13474 ns/iter (+/- 245) 14540 ns/iter (+/- 452) 0.93
example1 17720 ns/iter (+/- 124) 18226 ns/iter (+/- 511) 0.97
example2 414250 ns/iter (+/- 56,461) 382128 ns/iter (+/- 40,058) 1.1
example3 19436 ns/iter (+/- 341) 20345 ns/iter (+/- 497) 0.96
example4 13634 ns/iter (+/- 204) 14136 ns/iter (+/- 305) 0.96
example5 484799 ns/iter (+/- 34,537) 487339 ns/iter (+/- 38,210) 0.99
example6 10698 ns/iter (+/- 218) 11084 ns/iter (+/- 206) 0.97
example7 14897 ns/iter (+/- 215) 15678 ns/iter (+/- 364) 0.95
example8 14775 ns/iter (+/- 204) 15407 ns/iter (+/- 393) 0.96
example10 448771 ns/iter (+/- 49,422) 429916 ns/iter (+/- 38,885) 1.0
example4_template 12442 ns/iter (+/- 190) 13017 ns/iter (+/- 279) 0.96
build_rg_with_short_help 12182 ns/iter (+/- 195) 13026 ns/iter (+/- 317) 0.94
build_rg_with_long_help 12861 ns/iter (+/- 152) 13480 ns/iter (+/- 277) 0.95
write_rg_short_help 114389 ns/iter (+/- 1,663) 121387 ns/iter (+/- 2,170) 0.94
write_rg_long_help 260055 ns/iter (+/- 7,194) 270861 ns/iter (+/- 7,886) 0.96
parse_rg 26206 ns/iter (+/- 386) 29213 ns/iter (+/- 416) 0.90
parse_rg_with_complex 37610 ns/iter (+/- 604) 43995 ns/iter (+/- 873) 0.85
parse_rg_with_lots 847968 ns/iter (+/- 9,587) 995703 ns/iter (+/- 12,349) 0.85
build_rustup 14562 ns/iter (+/- 230) 15569 ns/iter (+/- 243) 0.94
parse_rustup 18150 ns/iter (+/- 271) 19650 ns/iter (+/- 316) 0.92
parse_rustup_with_sc 17755 ns/iter (+/- 166) 19935 ns/iter (+/- 415) 0.89

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.