Skip to content

Commit f773968

Browse files
Avoid a few useless, short-lived allocations
1 parent 41c4c14 commit f773968

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/report/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ pub fn generate_report<DB: ReadResults>(
243243
})
244244
});
245245
// Convert errors to Nones
246-
let mut crate_results = crate_results.map(|r| r.ok()).collect::<Vec<_>>();
247-
let crate2 = crate_results.pop().unwrap();
248-
let crate1 = crate_results.pop().unwrap();
246+
let mut crate_results = crate_results.map(|r| r.ok());
247+
let crate1 = crate_results.next().unwrap();
248+
let crate2 = crate_results.next().unwrap();
249249
let comp = compare(
250250
config,
251251
krate,

src/results/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@ macro_rules! test_result_enum {
125125

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

130-
if parts.len() == 1 {
131-
match parts[0] {
132+
if part2.is_none() {
133+
match part1 {
132134
$($with_reason_repr => Ok($name::$with_reason_name($reason::Unknown)),)*
133135
$($reasonless_repr => Ok($name::$reasonless_name),)*
134136
other => Err(TestResultParseError::UnknownResult(other.into()).into()),
135137
}
136138
} else {
137-
match parts[0] {
139+
match part1 {
138140
$($reasonless_repr => Err(TestResultParseError::UnexpectedFailureReason.into()),)*
139-
$($with_reason_repr => Ok($name::$with_reason_name(parts[1].parse()?)),)*
141+
$($with_reason_repr => Ok($name::$with_reason_name(part2.unwrap().parse()?)),)*
140142
other => Err(TestResultParseError::UnknownResult(other.into()).into()),
141143
}
142144
}

0 commit comments

Comments
 (0)