Skip to content

Commit

Permalink
Avoid a few useless, short-lived allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Dec 22, 2023
1 parent 54682e1 commit f17d602
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ pub fn generate_report<DB: ReadResults>(
})
});
// Convert errors to Nones
let mut crate_results = crate_results.map(|r| r.ok()).collect::<Vec<_>>();
let crate2 = crate_results.pop().unwrap();
let crate1 = crate_results.pop().unwrap();
let mut crate_results = crate_results.map(|r| r.ok());
let crate1 = crate_results.next().unwrap();
let crate2 = crate_results.next().unwrap();
let comp = compare(
config,
krate,
Expand Down
12 changes: 7 additions & 5 deletions src/results/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ macro_rules! test_result_enum {

fn from_str(input: &str) -> Fallible<Self> {
// if there is more than one ':' we assume it's part of a failure reason serialization
let parts: Vec<&str> = input.splitn(2, ':').collect();
let mut parts = input.splitn(2, ':');
let part1 = parts.next().unwrap();
let part2 = parts.next();

if parts.len() == 1 {
match parts[0] {
if part2.is_none() {
match part1 {
$($with_reason_repr => Ok($name::$with_reason_name($reason::Unknown)),)*
$($reasonless_repr => Ok($name::$reasonless_name),)*
other => Err(TestResultParseError::UnknownResult(other.into()).into()),
}
} else {
match parts[0] {
match part1 {
$($reasonless_repr => Err(TestResultParseError::UnexpectedFailureReason.into()),)*
$($with_reason_repr => Ok($name::$with_reason_name(parts[1].parse()?)),)*
$($with_reason_repr => Ok($name::$with_reason_name(part2.unwrap().parse()?)),)*
other => Err(TestResultParseError::UnknownResult(other.into()).into()),
}
}
Expand Down

0 comments on commit f17d602

Please sign in to comment.