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