I have this PR to once_cell, that adds a
unsafe fn get_unchecked(&self) -> &T method, which skips initialization check. Note that, as of now, API of once_cell is fully safe.
Looking at the assembly proves that this
get_unchecked method indeed can help with eliminating an atomic load, which can't be eliminated by using
get_unchecked at the call site. So there's no doubt that there are cases where
get_unchecked will be helpful.
So, adding this method can help some use-cases.
On the other hand, if I have this method, it could be misued. Roughly, if there are
1000 users of the crate, and one of them really needs
get_unchecked, there's some chance than one of the rest of the users will incorrectly use
unsafe. The math here is that the number of people for whom this method would be useful is much smaller than the total number of users of once_cell.
Should I, as a crate author, police the users and just don't provide the
unsafe method? Or should I consider misuse of unsafe to be of the marginal probability, and lean towards providing maximal performance?