simplify Option::get_or_insert

This commit is contained in:
Aleksey Kladov 2019-07-03 20:17:05 +03:00
parent 8301de16da
commit c51802ac60
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