mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #116481 - scottmcm:tweak-combinators, r=cuviper
Reuse existing `Some`s in `Option::(x)or` LLVM still has trouble re-using discriminants sometimes when rebuilding a two-variant enum, so when we have the correct variant already built, just use it. That's shorter in the Rust code, as well as simpler in MIR and the optimized LLVM, so might as well: <https://rust.godbolt.org/z/KhdE8eToW> Thanks to `@veber-alex` for pointing out this opportunity in https://github.com/rust-lang/rust/issues/101210#issuecomment-1732470941
This commit is contained in:
commit
f8dae0c20a
@ -1475,7 +1475,7 @@ impl<T> Option<T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn or(self, optb: Option<T>) -> Option<T> {
|
||||
match self {
|
||||
Some(x) => Some(x),
|
||||
x @ Some(_) => x,
|
||||
None => optb,
|
||||
}
|
||||
}
|
||||
@ -1500,7 +1500,7 @@ impl<T> Option<T> {
|
||||
F: FnOnce() -> Option<T>,
|
||||
{
|
||||
match self {
|
||||
Some(x) => Some(x),
|
||||
x @ Some(_) => x,
|
||||
None => f(),
|
||||
}
|
||||
}
|
||||
@ -1530,8 +1530,8 @@ impl<T> Option<T> {
|
||||
#[stable(feature = "option_xor", since = "1.37.0")]
|
||||
pub fn xor(self, optb: Option<T>) -> Option<T> {
|
||||
match (self, optb) {
|
||||
(Some(a), None) => Some(a),
|
||||
(None, Some(b)) => Some(b),
|
||||
(a @ Some(_), None) => a,
|
||||
(None, b @ Some(_)) => b,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user