matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.87k stars 109 forks source link

Nit: unnecessary synchronization in `Lazy::force_mut()` #226

Closed danielhenrymantilla closed 1 year ago

danielhenrymantilla commented 1 year ago

Self::force() has to synchronize the access to the raw value and/or its needed initialization, given its &-based API, but force_mut() does not, thanks to the guarantees of &mut access (e.g., https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html#method.get_mut).

But the current implementation of force_mut() just defers to force():

https://github.com/matklad/once_cell/blob/35148638c54c6233545c65d1a5e09d5ba0661806/src/lib.rs#L767-L770

matklad commented 1 year ago

Yup, this indeed should be improved!