Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Make `filled_with` more generic and recover from panics better. #4
slightlyoutofphase left a comment •
Sorry it took me a bit to respond! Needed a little more time to consider than the other PR. Your idea is great WRT to the panic stuff, and using a
That said, after looking at some assembler output, your code as written seems to inhibit the auto-vectorization of the initialization loop even in the best case scenario (release mode, no panic actually happens, etc.)
I played around with it a bit though, and found that the following has all of your intended benefits as far as dropping the items when things do go wrong, while also not preventing optimizations when things go fine:
If you want to switch it out in your branch for that (so you can still get "credit" for the commit), I'm happy to merge it right away.
GENERIC INITIALIZER: The initializer is now an `F: FnMut() -> T`, allowing, for example, using a stateful closure to initialize the vec. PANIC RECOVERY: If the initializer of `filled_with` panics, items pushed prior to the panic will be dropped.
For sure. That's basically why I always use
Thanks again for the contribution BTW, I probably wouldn't have ever thought to use FnMut or improve the panic handling on my own.