1 parent 8301de1 commit c51802aCopy full SHA for c51802a
1 file changed
src/libcore/option.rs
@@ -777,15 +777,7 @@ impl<T> Option<T> {
777
#[inline]
778
#[stable(feature = "option_entry", since = "1.20.0")]
779
pub fn get_or_insert(&mut self, v: T) -> &mut T {
780
- match *self {
781
- None => *self = Some(v),
782
- _ => (),
783
- }
784
-
785
786
- Some(ref mut v) => v,
787
- None => unsafe { hint::unreachable_unchecked() },
788
+ self.get_or_insert_with(|| v)
789
}
790
791
/// Inserts a value computed from `f` into the option if it is [`None`], then
0 commit comments