Skip to content

Commit 5d30ce6

Browse files
Mattias Wallinytmimi
Mattias Wallin
authored andcommitted
Avoid allocating intermediate strings in determine_operation
1 parent 9d407bf commit 5d30ce6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Diff for: src/bin/main.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,15 @@ fn print_version() {
462462

463463
fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
464464
if matches.opt_present("h") {
465-
let topic = matches.opt_str("h");
466-
if topic.is_none() {
465+
let Some(topic) = matches.opt_str("h") else {
467466
return Ok(Operation::Help(HelpOp::None));
468-
} else if topic == Some("config".to_owned()) {
469-
return Ok(Operation::Help(HelpOp::Config));
470-
} else if topic == Some("file-lines".to_owned()) && is_nightly() {
471-
return Ok(Operation::Help(HelpOp::FileLines));
472-
} else {
473-
return Err(OperationError::UnknownHelpTopic(topic.unwrap()));
474-
}
467+
};
468+
469+
return match topic.as_str() {
470+
"config" => Ok(Operation::Help(HelpOp::Config)),
471+
"file-lines" if is_nightly() => Ok(Operation::Help(HelpOp::FileLines)),
472+
_ => Err(OperationError::UnknownHelpTopic(topic)),
473+
};
475474
}
476475
let mut free_matches = matches.free.iter();
477476

0 commit comments

Comments
 (0)