Remove unnecessary unsafe {} blocks; remove an unnecessary allocation (String -> str for immediately-discarded debug message)

This commit is contained in:
Árpád Goretity 2017-10-04 22:38:45 +02:00
parent 3224e2e1cd
commit cad2e64bdf
2 changed files with 7 additions and 8 deletions

View file

@ -847,12 +847,11 @@ impl<'a> Help<'a> {
_ => continue,
};
debugln!("Help::write_template_help:iter: tag_buf={};", unsafe {
String::from_utf8_unchecked(tag_buf.get_ref()[0..tag_length]
.iter()
.map(|&i| i)
.collect::<Vec<_>>())
});
debugln!(
"Help::write_template_help:iter: tag_buf={};",
str::from_utf8(&tag_buf.get_ref()[..tag_length])
.unwrap_or_default()
);
match &tag_buf.get_ref()[0..tag_length] {
b"?" => {
self.writer.write_all(b"Could not decode tag name")?;

View file

@ -1352,7 +1352,7 @@ impl<'a, 'b> Parser<'a, 'b>
match Help::write_parser_help(&mut buf, self, use_long) {
Err(e) => e,
_ => Error {
message: unsafe { String::from_utf8_unchecked(buf) },
message: String::from_utf8(buf).unwrap_or_default(),
kind: ErrorKind::HelpDisplayed,
info: None,
}
@ -1566,7 +1566,7 @@ impl<'a, 'b> Parser<'a, 'b>
if no_val && min_vals_zero && !has_eq && needs_eq {
debugln!("Parser::parse_opt: More arg vals not required...");
return Ok(ParseResult::ValuesDone);
} else if no_val || (mult && !needs_delim) && !has_eq && matcher.needs_more_vals(opt) {
} else if no_val || (mult && !needs_delim) && !has_eq && matcher.needs_more_vals(opt) {
debugln!("Parser::parse_opt: More arg vals required...");
return Ok(ParseResult::Opt(opt.b.name));
}