From 2482c095b1c467ad32a61401810d356513ee7500 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 28 Dec 2018 13:59:44 +0100 Subject: [PATCH] getopt: remove skip logic The 'skip' variable was set to indicate that the "rest of the args" is to be copied into the 'rest' vec. We can do this directly and avoid the 'if' case in the loop altogether. Signed-off-by: Wolfgang Bumiller --- src/getopts.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/getopts.rs b/src/getopts.rs index 517cc372..31f6f61f 100644 --- a/src/getopts.rs +++ b/src/getopts.rs @@ -67,18 +67,10 @@ pub fn parse_arguments( let mut pos = 0; - let mut skip = false; - while pos < args.len() { - if skip { - rest.push(args[pos].clone()); - pos += 1; - continue; - } - match parse_argument(&args[pos]) { RawArgument::Separator => { - skip = true; + break; } RawArgument::Option { name, value } => { match value { @@ -142,6 +134,8 @@ pub fn parse_arguments( pos += 1; } + rest.extend_from_slice(&args[pos..]); + for i in 0..arg_param.len() { if rest.len() > i { data.push((arg_param[i].to_string(), rest[i].clone()));