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

adding get_unchecked_mut #216

Closed bobi6666 closed 1 year ago

bobi6666 commented 1 year ago

hello is there any steps how you can add get_unchecked_mut()? it can be used for example with rand crate on my side

matklad commented 1 year ago

What would be the signature of this method?

bobi6666 commented 1 year ago

i think fn get_unchecked_mut

2023-01-15 16:32 GMT+01:00, Alex Kladov @.***>:

What would be the signature of this method?

-- Reply to this email directly or view it on GitHub: https://github.com/matklad/once_cell/issues/216#issuecomment-1383181097 You are receiving this because you authored the thread.

Message ID: @.***>

notgull commented 1 year ago

There is already a get_mut method that I think does what you want

bobi6666 commented 1 year ago

yes but get_unchecked is lot faster when i using that when i am sure my cell is initialized and for this reason get_unchecked_mut would be also faster. normal get is slower when you are not sure if you initialized or not

2023-01-15 19:28 GMT+01:00, John Nunley @.***>:

There is already a get_mut method that I think does what you want

-- Reply to this email directly or view it on GitHub: https://github.com/matklad/once_cell/issues/216#issuecomment-1383219473 You are receiving this because you authored the thread.

Message ID: @.***>

matklad commented 1 year ago

You can use get_mut().unwrap_unchecked(). Though, I would encourage to verify via benchmarks that that’s indeed faster for your use case.