Skip to content

Commit c51802a

Browse files
committed
simplify Option::get_or_insert
1 parent 8301de1 commit c51802a

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/libcore/option.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -777,15 +777,7 @@ impl<T> Option<T> {
777777
#[inline]
778778
#[stable(feature = "option_entry", since = "1.20.0")]
779779
pub fn get_or_insert(&mut self, v: T) -> &mut T {
780-
match *self {
781-
None => *self = Some(v),
782-
_ => (),
783-
}
784-
785-
match *self {
786-
Some(ref mut v) => v,
787-
None => unsafe { hint::unreachable_unchecked() },
788-
}
780+
self.get_or_insert_with(|| v)
789781
}
790782

791783
/// Inserts a value computed from `f` into the option if it is [`None`], then

0 commit comments

Comments
 (0)