diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-04 01:39:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-04 01:39:01 +0200 |
| commit | 839e89c3d113ac80bc1bdc9383a3cd64ba4e9582 (patch) | |
| tree | 13a3923806856502c39a2158a8a85b37093d6d29 | |
| parent | cd1fa00446e438407f58a0c9d70c712a8e4f1e80 (diff) | |
| parent | c51802ac6087206e302bbded174d5ac9feabf2b7 (diff) | |
| download | rust-839e89c3d113ac80bc1bdc9383a3cd64ba4e9582.tar.gz rust-839e89c3d113ac80bc1bdc9383a3cd64ba4e9582.zip | |
Rollup merge of #62344 - matklad:simplify-option, r=sfackler
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!
| -rw-r--r-- | src/libcore/option.rs | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index a2eff0200b7..b27fd4098e1 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -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 |
