mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Don't inline OnceCell initialization closures
This commit is contained in:
parent
237bb5e008
commit
ca2d2fa283
@ -214,7 +214,16 @@ impl<T> OnceCell<T> {
|
|||||||
if let Some(val) = self.get() {
|
if let Some(val) = self.get() {
|
||||||
return Ok(val);
|
return Ok(val);
|
||||||
}
|
}
|
||||||
let val = f()?;
|
/// Avoid inlining the initialization closure into the common path that fetches
|
||||||
|
/// the already initialized value
|
||||||
|
#[cold]
|
||||||
|
fn outlined_call<F, T, E>(f: F) -> Result<T, E>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> Result<T, E>,
|
||||||
|
{
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
let val = outlined_call(f)?;
|
||||||
// Note that *some* forms of reentrant initialization might lead to
|
// Note that *some* forms of reentrant initialization might lead to
|
||||||
// UB (see `reentrant_init` test). I believe that just removing this
|
// UB (see `reentrant_init` test). I believe that just removing this
|
||||||
// `assert`, while keeping `set/get` would be sound, but it seems
|
// `assert`, while keeping `set/get` would be sound, but it seems
|
||||||
|
Loading…
Reference in New Issue
Block a user