You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an issue in which using push_unchecked in loops, even with a fixed number of iterations, causes inferior assembly to be generated. For example:
The workaround is to manually push by writing directly to self.data and incrementing self.length. However, we'd prefer to minimize the amount of unsafe code we have to write, and we'd rather use "safer unsafes" like push_unchecked that provide a friendlier contract than self.data.get_unchecked_mut().write.
The text was updated successfully, but these errors were encountered:
I honestly think it has something to do with the fact that MaybeUninit::write in fact has a return value, which is a mutable reference to whatever you just wrote to it.
The docs state this is for your convenience, although IMO it seems like a somewhat strange API. So it may even be that using regular pointer writes in the troublesome spots turns out to work more efficiently (although IIRC that left me with Miri errors at some point early on, because I guess in some cases it wasn't considered the "same" as using the built-in MaybeUninit::write, although generally it should be.)
I'll experiment with some things when I have a bit more time later on to see if I can arrive at a solution that's both fast and sound.
I'd say push_unchecked is now basically being used where it makes sense to use it (except for filled_with still, but that seems to be a particularly special case.)
There's an issue in which using
push_unchecked
in loops, even with a fixed number of iterations, causes inferior assembly to be generated. For example:staticvec/src/lib.rs
Lines 116 to 133 in 4b2534f
The workaround is to manually push by writing directly to
self.data
and incrementingself.length
. However, we'd prefer to minimize the amount of unsafe code we have to write, and we'd rather use "safer unsafes" likepush_unchecked
that provide a friendlier contract thanself.data.get_unchecked_mut().write
.The text was updated successfully, but these errors were encountered: