Rollup merge of #62344 - matklad:simplify-option, r=sfackler

simplify Option::get_or_insert

I am pretty sure that the optimized result will be the same, and it's one `unsafe` less in the stdlib!
This commit is contained in:
Mazdak Farrokhzad 2019-07-04 01:39:01 +02:00 committed by GitHub
commit 839e89c3d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 9 deletions

View File

@ -777,15 +777,7 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_entry", since = "1.20.0")]
pub fn get_or_insert(&mut self, v: T) -> &mut T {
match *self {
None => *self = Some(v),
_ => (),
}
match *self {
Some(ref mut v) => v,
None => unsafe { hint::unreachable_unchecked() },
}
self.get_or_insert_with(|| v)
}
/// Inserts a value computed from `f` into the option if it is [`None`], then