Skip to content

Commit

Permalink
Rollup merge of rust-lang#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 authored Jul 3, 2019
2 parents ed6c9ea + c51802a commit 773b1b9
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 773b1b9

Please sign in to comment.