Skip to content

Commit

Permalink
simplify Option::get_or_insert
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jul 3, 2019
1 parent 8301de1 commit c51802a
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c51802a

Please sign in to comment.