Skip to content

Commit

Permalink
Rollup merge of #62344 - matklad:simplify-option, r=sfackler
Browse files Browse the repository at this point in the history
simplify Option::get_or_insert

I am pretty sure that the optimized result will be the same, and it's one `unsafe` less in the stdlib!
  • Loading branch information
Centril committed Jul 3, 2019
2 parents cd1fa00 + c51802a commit 839e89c
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 839e89c

Please sign in to comment.