未验证 提交 839e89c3 编写于 作者: M Mazdak Farrokhzad 提交者: GitHub

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!
......@@ -777,15 +777,7 @@ pub fn xor(self, optb: Option<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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册