Skip to content

Commit c85bfc5

Browse files
committed
assert-less intern_with
1 parent 256335b commit c85bfc5

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/librustc/ty/context.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,29 +2862,27 @@ impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
28622862
-> Self::Output {
28632863
// This code is hot enough that it's worth specializing for the most
28642864
// common length lists, to avoid the overhead of `SmallVec` creation.
2865-
// The match arms are in order of frequency. The 1, 2, and 0 cases are
2866-
// typically hit in ~95% of cases. We assume that if the upper and
2867-
// lower bounds from `size_hint` agree they are correct.
2868-
Ok(match iter.size_hint() {
2869-
(1, Some(1)) => {
2870-
let t0 = iter.next().unwrap()?;
2871-
assert!(iter.next().is_none());
2872-
f(&[t0])
2873-
}
2874-
(2, Some(2)) => {
2875-
let t0 = iter.next().unwrap()?;
2876-
let t1 = iter.next().unwrap()?;
2877-
assert!(iter.next().is_none());
2878-
f(&[t0, t1])
2879-
}
2880-
(0, Some(0)) => {
2881-
assert!(iter.next().is_none());
2882-
f(&[])
2883-
}
2884-
_ => {
2885-
f(&iter.collect::<Result<SmallVec<[_; 8]>, _>>()?)
2886-
}
2887-
})
2865+
// In terms of frequency, lengths 1, 2, and 0 are typically hit in ~95% of cases.
2866+
let e0 = match iter.next() {
2867+
Some(x) => x?,
2868+
None => return Ok(f(&[])),
2869+
};
2870+
let e1 = match iter.next() {
2871+
None => return Ok(f(&[e0])),
2872+
Some(x) => x?,
2873+
};
2874+
let e2 = match iter.next() {
2875+
None => return Ok(f(&[e0, e1])),
2876+
Some(x) => x?,
2877+
};
2878+
let mut vec: SmallVec<[_; 8]> = SmallVec::with_capacity(3 + iter.size_hint().0);
2879+
vec.push(e0);
2880+
vec.push(e1);
2881+
vec.push(e2);
2882+
for result in iter {
2883+
vec.push(result?);
2884+
}
2885+
Ok(f(&vec))
28882886
}
28892887
}
28902888

0 commit comments

Comments
 (0)